0

我有一个项目,它只为测试目的构建 fat onejar 文件。因此,我不希望有一个单独的测试类作为对主源的依赖,但我确实希望它包含在 onejar 中。奇怪的场景,我知道。

我正在使用com.smokejumperit.gradle.OneJarPlugin插件(source here),很明显它会在这里获取要包含在 onejar 中的文件列表:

project.task('oneJar', dependsOn:[project.tasks.jar, project.tasks.typedefOneJar]) {
    ...
    inputs.files([jar.outputs.files, project.configurations.getByName("compile"), project.configurations.getByName("runtime")])

jar.output.files用于发布,所以我不希望发布第二个 jar 文件,并且两者project.configurations将为主要源 jar 定义依赖项,我也不希望第二个 jar 成为该文件的依赖项。

第二个 jar 文件是用一个任务构建的:

task integrationJar(type: Jar) {
    from sourceSets.integrationTest.output
    classifier = 'integration'
}

...所以我可以通过integrationJar.outputs.files. 如果有一种明确的方法可以将其添加到oneJar.input.files,我会很高兴,但我无法弄清楚如何做到这一点。我试过这样的事情:

oneJar {
    dependsOn 'integrationJar'
    println integrationJar.outputs.files.getAsPath()
    inputs.files.add(integrationJar.outputs.files)
    println inputs.files.getAsPath()
}

...但最后一次打印的结果仍然缺少集成 jar 文件。

想法?

4

1 回答 1

1

I'm not familiar with the implementation of that plugin, but I'd be surprised if inputs.files determined what gets included. (Usually, inputs is just consumed by Gradle's up-to-date check.) I recommend to try the gradle-one-jar plugin, which appears to be more flexible.

于 2013-07-26T16:56:15.793 回答