Closed BPaasch closed 7 years ago
The repackaging includes everything in the runtime
configuration which is why dependencies in the api
and implementation
configurations are not being included. 2.0 snapshots are not affected by this problem as the new bootJar
task doesn't deal with configurations directly. Instead, it uses the runtime class path of the main source set.
In 1.5 and earlier, you can configure a custom configuration that will have its dependencies packaged in the jar. Ideally, this would be possible:
bootRepackage {
customConfiguration = 'implementation'
}
Unfortunately, it fails as Gradle does not allow the implementation
configuration to be resolved directly. Instead, you need to introduce some indirection in the form of another configuration that extends implementation
:
configurations {
custom {
it.extendsFrom implementation
}
}
bootRepackage {
customConfiguration = 'implementation'
}
With this in place, both commons-math3
and guava
are included in the jar.
I also meant to say above that it seems rather strange to me to be applying Gradle's Library plugin to a project that's building a Spring Boot Application. It's rather rare (and not recommended) for a Spring Boot application to be used as a dependency so I'm surprised that you'd want to build it as a library. Have I missed a usecase here?
Thank you for the explanation. I figured that there might be some configuration to get it to work.
Also, no there's no missed use-case. I realize now that I should have been using the Java plugin all along. For some reason, I thought that the Java plugin was being replaced by the Java Library plugin.
@wilkinsona thank you for posting the workaround, it helped me use the new implementation
dependency type in Gradle 4.7 (as compile
is deprecated in both the Java plugin and the Java Library plugin). I had to change it to customConfiguration = 'custom'
to match the new configuration's name
@wilkinsona This is very interesting, I think this workaround should be documented somewhere here : https://docs.spring.io/spring-boot/docs/1.5.20.RELEASE/reference/html/build-tool-plugins-gradle-plugin.html. And indeed compile
configuration is deprecated in the java-plugin as well : https://docs.gradle.org/5.3.1/userguide/java_plugin.html#tab:configurations.
I know that Spring Boot 1.5.x is reaching end of life soon, but it allows a decoupled migration path for those that updates their gradle configuration first.
May add it.extendsFrom runtimeOnly
also.
Bug report
When using the new Gradle Java Library plugin and declaring dependencies using the api or implementation configurations, the bootRepackage task doesn't package the dependencies into the final jar.
If I replace the declared dependencies using the compile configuration, then the bootRepackage task does package them into the jar. However, the gradle documentation says to ignore this configuration:
Example: