gradlex-org / extra-java-module-info

A Gradle 6.8+ plugin to use legacy Java libraries as Java Modules in a modular Java project
Apache License 2.0
103 stars 6 forks source link

How do I save the transformed module so it can be deployed? #139

Closed dahuber-github closed 1 month ago

dahuber-github commented 1 month ago

First, thanks for this. This saved me serious amount of time in our product upgrade.

I need to deploy our product into a docker container. I need to include our build artifacts as well as the library dependencies. When I use this tool to transform a dependency, my output folder (dependencies) is get the original jar (un-transformed) as output.

I'm doing something like this....

configurations {
  localApi
  localImplementation
}

dependencies {

  localApi (group: 'com.google.guava', name: 'guava', version: '33.2.1-jre')
  ...

  localImplementation (group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.17.1')
  ...

  /* This is the magic to include the local configuration into the actual path */
  configurations.api.extendsFrom(configurations.localApi)
  configurations.implementation.extendsFrom(configurations.localImplementation)
}

task copyToDependencies(type: Copy) {
    delete "$buildDir/dependencies"

    into "$buildDir/dependencies"
    from configurations.localApi
    from configurations.localImplementation
}
copyToDependencies.mustRunAfter Jar

Thank you for your help.

jjohannes commented 1 month ago

Thank you for your interest in the plugin. For custom Configurations, such as your localImplementation and localApi, you need to set the attribute javaModule = true in order to activate the plugin's functionality. This is the reverse of what the Readme describes here.

In your case, it should look roughly like this:

configurations {
    localApi {
        attributes { attribute(Attribute.of("javaModule", Boolean), true) }
        attributes { attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) }
    }
}

Since you did not use attributes on your custom Configurations before, you use legacy Gradle behavior. That's why you most likely also need to set the Usage attribute (it may work without that line).


There is an open feature request to add a simpler configuration option for this which we will add in a future version. Then I'll also extend the Readme to cover this better.

dahuber-github commented 1 month ago

That fixed it. Thank you for your help and for creating such a useful plugin.