Gradle-将外部项目作为依赖项包含到.jar中

时间:2019-03-27 14:22:59

标签: eclipse gradle jar executable-jar multi-project

我有两个项目是依赖项:A,B。(没有子项目,但是 EXTERNAL项目

我的第三个项目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 相关的“不包括依赖项” 的错误。类。

有人已经解决了这个问题? 谢谢!

1 个答案:

答案 0 :(得分:0)

这可能对解释创建包含依赖罐的胖罐子很有用。 https://www.baeldung.com/gradle-fat-jar