:samples-dir: /home/tcagent1/agent/work/64493a816be20d5a/promote-projects/gradle/build/git-checkout/platforms/documentation/docs/build/working/samples/install/java-modules-with-transform
:gradle-version: 9.2.0-milestone-2

= Building Java Modules with Legacy Libraries Sample

[.download]
- link:zips/sample_java_modules_with_transform-groovy-dsl.zip[icon:download[] Groovy DSL]
- link:zips/sample_java_modules_with_transform-kotlin-dsl.zip[icon:download[] Kotlin DSL]

NOTE: You can open this sample in an link:{userManualPath}/gradle_ides.html#gradle_ides[IDE that supports Gradle].

This sample shows how link:{userManualPath}/artifact_transforms.html[artifact transforms] can be utilised to turn traditional Java libraries into Java Modules by adding additional information to the corresponding Jars.
For that, a plugin called `extra-java-module-info` is defined in the `buildSrc` folder.
This plugin can be copied into another project and adjusted as needed to solve use cases where it is desired to treat every dependency as a Java Module.

NOTE: A further evolved version of the plugin shown in this example is published by the GradleX project and can be used directly: https://plugins.gradle.org/plugin/org.gradlex.extra-java-module-info[org.gradlex.extra-java-module-info]

The example defines an application that relies on libraries from Maven central where some of them are not available as modules.
It uses `commons-cli` (not a module) to parse the command line arguments, which can contain a JSON String, and `gson` (a proper module) to parse the JSON string.
It also utilises `commons-lang3` (an automatic module) and `commons-beanutils` (not a module) which brings in some additional dependencies that are also not modules.

By configuring our own `extra-java-module-info` plugin, we add information to turn the legacy libraries into modules.

====
include::sample[dir="kotlin",files="application/build.gradle.kts[tags=extraModuleInfo]"]
include::sample[dir="groovy",files="application/build.gradle[tags=extraModuleInfo]"]
====

You can run the example application like this:

```
run --args='-json {"message":"Hello","receivers":["Lisa","John"]} -debug'
```

For more information, see link:{userManualPath}/java_library_plugin.html#sec:java_library_modular[Java Module support in the Java Library Plugin] and link:{userManualPath}/application_plugin.html#sec:application_modular[Java Module support in the Application Plugin].
