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

标签 eclipse gradle jar executable-jar multi-project

我有两个项目是依存关系: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/

相关文章:

batch-file - 如何将参数从 gradle exec 任务传递到命令行

java - foo.jar 未标记为可执行文件

android - Gradle 命令行 : failed to find target android-22

gradle - 如何使用Kotlin,Gradle和Web框架设置Spring Loaded?

java - 将 jar 文件从 Windows 7 复制到 Unix 会出现 java.util.zip.ZipException

java - 从 JAR 中提取和加载 DLL

java - Eclipse 中 Gradle 任务的 Stacktrace 选项

eclipse - Eclipse“HELIOS”上的Zend Studio

java - Eclipse PDT 插件给我带来了麻烦

java - Spring 3 和 Junit 4 NullPointerException