我有两个项目是依存关系:A,B。
我的第三个项目C,同时取决于A和B。
我已经以这种方式定义了settings.gradle:
settings.gradle
rootProject.name = 'project_C'
include ':common_library'
project(":project_A").projectDir = file("../project_A")
include ':project_A'
project(":project_B").projectDir = file("../project_B")
build.gradle
// ************** Include dependencies as local .jars
implementation fileTree(include: ['*.jar'], dir: 'lib')
// ************** Compile the project on which this depends on
implementation project(':project_A')
implementation project(':project_B')
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
// *********** MODIFY the standard JAR task, including Main file (for executable jars) and pack all it's dependencies
jar {
from {
(configurations.runtime).collect {
configurations.runtime.filter( {! (it.name =~ /.*\.pom/ )}).collect {
it.isDirectory() ? it : zipTree(it)
}
}
}
manifest {
attributes "Main-Class": "Main"
}
}
至此,的构建成功了。
但是,当我尝试以jar形式执行它时,它给了我有关“不包括依赖项” 的错误,该错误与 project_A 和 project_B 类有关。
有人已经解决了这个问题?
谢谢!
最佳答案
这可能对解释创建包含从属jar的胖jar很有用。
https://www.baeldung.com/gradle-fat-jar
关于eclipse - Gradle-将外部项目作为依赖项包含到.jar中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55379576/