0

I have a project that only builds the fat onejar file for testing purposes. Thus, there's a separate testing class that I don't want as a dependency to the main source, but I do want it included into the onejar. Odd scenario, I know.

I'm using the com.smokejumperit.gradle.OneJarPlugin plugin (source here), and clearly it gets the list of files to include in the onejar here:

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 is used for publishing, so I don't want a this second jar file being published, and the two project.configurations would define dependencies for the main source jar, and I don't want this second jar to be a dependency of that either.

This second jar file is built with a task:

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

... so I can access the resulting FileCollection via integrationJar.outputs.files. If there was a clear way to add that to oneJar.input.files, I'd be golden, but I can't figure out how to do that. I've tried something like this:

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

... but the result for the last print is still missing the integration jar file.

Ideas?

Depressio
  • 1,329
  • 2
  • 20
  • 39
  • Just put a dummy class in the main source that depends on the jar in question. Ugly but effective. – Lee Meador Jul 26 '13 at 16:41
  • Not sure what you mean, exactly. Can you give an example? The integration jar file is separate because it has some dependencies I don't want the main source to have (like jetty). Do you mean a class that simply loads the jar file into the classpath or something? Not sure what that might look like. – Depressio Jul 26 '13 at 17:05

1 Answers1

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.

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259