Consuming Java Modules (not in modules.properties)
Closed this issue · 5 comments
My project requires two modules, module-info.java
.
...
// https://github.com/decorators-squad/eo-yaml/blob/master/src/main/java9/module-info.java
requires com.amihaiemil.eoyaml;
...
// https://github.com/remkop/picocli/blob/main/src/main/java9/module-info.java
requires info.picocli;
Looking at the documentation
https://github.com/jjohannes/java-module-dependencies#add-module-name-mapping-information-if-needed
It seems that I need to provide the a map relating the module name to its ga
.
javaModuleDependencies {
moduleNameToGA.put("com.amihaiemil.eoyaml", "com.amihaiemil.web:eo-yaml")
moduleNameToGA.put("info.picocli", "info.picocli:picocli")
...
}
dependencies.constraints {
javaModuleDependencies {
api(gav("com.amihaiemil.web:eo-yaml", "6.0.1"))
api(gav("info.picocli:picocli", "4.6.3"))
...
}
...
}
This does not appear to work though.
[WARN] [Java Module Dependencies] No mapping registered for module: com.amihaiemil.eoyaml (required in cli/src/main/java/module-info.java) - use 'javaModuleDependencies.moduleNameToGA.put("com.amihaiemil.eoyaml", "group:artifact")' to add mapping.
Could not resolve: info.picocli:picocli
Could not resolve: info.picocli:picocli
Usage error?
Maven repository:
I found this fragment.
Which would suggest the following:
javaModuleDependencies {
moduleNameToGA.put("com.amihaiemil.eoyaml", "com.amihaiemil.web:eo-yaml")
moduleNameToGA.put("info.picocli", "info.picocli:picocli")
...
}
dependencies.constraints {
javaModuleDependencies {
api(gav("com.amihaiemil.eoyaml", "6.0.1"))
api(gav("info.picocli", "4.6.3"))
...
}
...
}
That does not seem to change the error messages.
I made a modification to your demo project to illustrate the issue.
https://github.com/jjohannes/gradle-project-setup-howto/compare/java_module_system...babeloff:java_module_system?expand=1
Hi @phreed. The way it technically works, the mappings are more comparable to dependency rules (component metadata rules) than dependency constraints. They cannot be 'injected' through a platform. Instead, they need to be registered for all projects in a convention plugin.
In the example, this is the place where the extra mappings are defined:
https://github.com/jjohannes/gradle-project-setup-howto/blob/java_module_system/gradle/plugins/dependency-rules-plugins/src/main/kotlin/org.example.java-modules-dependency-rules.gradle.kts#L37
If you move your mappings...
moduleNameToGA.put("com.amihaiemil.eoyaml", "com.amihaiemil.web:eo-yaml")
moduleNameToGA.put("info.picocli", "info.picocli:picocli")
...there, it should work.
@jjohannes thanks
I updated the sample to reflect your recommendation.
https://github.com/jjohannes/gradle-project-setup-howto/compare/java_module_system...babeloff:java_module_system?expand=1
It works as expected now.
Glad to hear. I added the two mappings you shared so they will be in the next release.