由于Spark2.0.0以上默认2.11.x编译,所以对用哪个版本,可以自己选择,可以让gradle自行导入,如果出现错误,可以再进行解决.
一下是具体的配置文件,包含打包Task.
setting.gradle
rootProject.name = 'TestGradle3'
build.gradle
group '项目包路径'
version '1.0-SNAPSHOT' apply plugin: 'java' /*add scala support*/ apply plugin: 'scala' sourceCompatibility = 1.8 repositories { mavenLocal() mavenCentral() } sourceSets{ main { scala{ srcDirs = ['src/main/scala'] } java{ srcDirs = ['src/main/java'] } resources{ srcDirs = ['src/main/resources'] } } test { scala{ srcDirs = ['src/test/scala'] } java{ srcDirs = ['src/test/java'] } resources{ srcDirs = ['src/test/resources'] } } } dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12' /* scala */ compile group: 'org.scala-lang', name: 'scala-library', version: '2.11.8' compile group: 'org.scala-lang', name: 'scala-compiler', version: '2.11.8' compile group: 'org.scala-lang', name: 'scalap', version: '2.11.8' /* spark */ compile group: 'org.apache.spark', name: 'spark-core_2.11', version: '2.2.0' /* hadoop */ compile group: 'org.apache.hadoop', name: 'hadoop-client', version: '2.7.3' /*mongodb java Driver*/ compile group: 'org.mongodb', name: 'mongo-java-driver', version: '3.4.2' /* spark connect to mongodb */ compile group: 'org.mongodb.spark', name: 'mongo-spark-connector_2.11', version: '2.2.1' /* fastjson */ compile group: 'com.alibaba', name: 'fastjson', version: '1.2.44'}