所以我的项目结构如下
root
|-- module-1
|-- module-2
.
.
|-- module-n
我们正在研究的最终工件是来自所有模块的所有来源的组合罐。我不确定这是否是正确的方法。 这是我的构建脚本:
plugins {
id "com.github.johnrengelman.shadow" version "1.2.3"
}
group = 'com.root'
version = System.getenv('BUILD_NUMBER') ?:'1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
configurations { providedCompile }
repositories {
mavenLocal()
mavenCentral()
}
def sparkVersion = '2.0.0'
def scalaMajorVersion = '2.11'
sourceSets {
main {
java {
srcDirs = ['module1/src/main/java', 'module2/src/main/java']
}
}
}
dependencies {
compile group: 'org.scala-lang', name:'scala-compiler', version:'2.11.8'
compile group: 'org.apache.kafka', name: 'kafka-clients', version: '0.9.0.0'
compile group: 'org.apache.spark', name: "spark-streaming-kafka_$scalaMajorVersion", version: '1.6.2'
compile group: 'org.apache.spark', name: "spark-streaming_$scalaMajorVersion", version: "$sparkVersion"
compile group: 'org.apache.spark', name: "spark-catalyst_$scalaMajorVersion", version: "$sparkVersion"
compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
compile group: 'org.apache.zookeeper', name: 'zookeeper', version: '3.4.9'
providedCompile group: 'org.apache.spark', name: "spark-core_$scalaMajorVersion", version: "$sparkVersion"
providedCompile group: 'org.apache.spark', name: "spark-sql_$scalaMajorVersion", version: "$sparkVersion"
testCompile group: 'junit', name: 'junit', version: '4.11'
}
build.dependsOn(shadowJar);
shadowJar {
zip64 true
}
sourceSets.main.compileClasspath += configurations.providedCompile
sourceSets.test.compileClasspath += configurations.providedCompile
sourceSets.test.runtimeClasspath += configurations.providedCompile
artifacts {
archives file: shadowJar.archivePath, builtBy: shadowJar
}
所以我们只是在添加新模块时附加sourceSets。
我只想确认这是否是构建多模块项目的正确方法,如果不是正确的方法?以及如何考虑模块间的依赖关系?
答案 0 :(得分:0)
您似乎在复制逻辑,因为每个模块都会将.java
编译为.class
,但是在汇总时会再次执行此操作。如果是我,我有以下模块
root
|-- module-1
|-- module-2
.
.
|-- module-n
+-- uber
在uber
模块中,我使用shadow来汇总已编译的.class
文件。您的uber/build.gradle
可能看起来像
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'
dependencies {
runtime project(':module-1')
runtime project(':module-2')
runtime project(':module-N')
}
shadowJar {
baseName = 'foo'
classifier = 'bar'
version = project.version
}