autoconfigure-gradle-plugin icon indicating copy to clipboard operation
autoconfigure-gradle-plugin copied to clipboard

The JavaLibraryPlugin must not be applied for project/module that is creating an executable artifact

Open MartinAhrer opened this issue 2 years ago • 7 comments

By default the JavaLibraryPlugin is applied to all modules (the project). The JavaLibraryPlugin only should be applied when producing a shareable library JAR. For an executable artifact it is sufficient to apply the JavaPlugin or in addition the application/SpringBoot plugin.

Having the JavaLibraryPlugin applied by default causes the Spring Boot native image build to try producing a dynamic link library instead of producing an executable.

Below is a first attempt to fix that

class JavaConfigurePlugin : Plugin<Project> {
    override fun apply(project: Project) {
        if (project.name.endsWith("-server")) { // TODO figure out how to use isServer()
            project.plugins.apply(JavaPlugin::class)
        } else {
            project.plugins.apply(JavaLibraryPlugin::class)
        }
...

MartinAhrer avatar Nov 28 '22 08:11 MartinAhrer

that is already merged since a couple of versions, forgot to close

klu2 avatar May 16 '23 14:05 klu2

now the "api" configuration is not available anymore: https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_separation

haraldradi avatar Dec 11 '23 11:12 haraldradi

* What went wrong:
A problem occurred evaluating project ':contract-client'.
> Could not find method api() for arguments [io.cloudflight.conto:conto-signature-api] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

haraldradi avatar Dec 11 '23 11:12 haraldradi

Also see https://github.com/cloudflightio/autoconfigure-gradle-plugin/issues/195

haraldradi avatar Dec 11 '23 11:12 haraldradi

Yes, as of #127 and #137 we decided to not apply the JavaLibraryPlugin automatically anymore at least in applicationBuilds. As we can only evaluate that property afterEvaluate, we decided to not apply the JavaLibraryPlugin at all any more. In case you need it, please apply it manually.

The problematic code here is that one: https://github.com/cloudflightio/autoconfigure-gradle-plugin/blob/main/src/main/kotlin/io/cloudflight/gradle/autoconfigure/java/JavaConfigurePlugin.kt#L69

We need to wait for afterEvaluate, and that's too late to apply the plugin.

klu2 avatar Dec 11 '23 13:12 klu2

This is quite a breaking change.

haraldradi avatar Dec 11 '23 15:12 haraldradi

The breaking change was marked with a new minor version because there wasn't a 1.0.0 released at that time. See https://github.com/cloudflightio/autoconfigure-gradle-plugin/releases/tag/0.9.0. In these release notes it is also written what to do if you still need the java-library plugin: If you need the api dependency scope, then please apply the java-library plugin in your modules yourself. For better clarity I've updated the documentation in https://github.com/cloudflightio/autoconfigure-gradle-plugin/pull/196. With this I kindly ask you to close this issue or state a reason to keep this issue opened.

rspiegl avatar Dec 11 '23 16:12 rspiegl