question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Gradle multiproject fails to find automatic-module-name with dependency on java-library.

See original GitHub issue

I have a Gradle multi-project build. One subproject (bitcoinj-core) is a Java 7 JAR with an Automatic-Module-Name manifest entry written in the jar task. The other subproject (wallettemplate) has a dependency on the Java 7 module declared as follows:

    implementation project(':bitcoinj-core')

The build fails with the following error:

/path/bitcoinj/wallettemplate/src/main/java/module-info.java:19: error: module not found: org.bitcoinj.core
        requires org.bitcoinj.core;     // Automatic module

Because Gradle detects bitcoinj-core is using the java-library plugin, the wallettemplate compile depends on the “class directory” output of bitcoinj-core, not the jar with the needed manifest entry.

I would like to see one or more of the following solutions:

a. Java Modules Plugin to handle this case gracefully and automatically b. Java Modules Plugin to include documentation or example for how to avoid this problem c. Gradle itself to provide better documentation on this issue and its resolution.

For ©, I’m going to report the issue directly to Gradle.

For the failing build see: https://travis-ci.org/github/msgilligan/bitcoinj/jobs/679852675 This bitcoinj PR (see https://github.com/bitcoinj/bitcoinj/pull/1779) was building correctly until it was rebased on an updated master branch where the bitcoinj-core module had been updated from the Gradle, java plugin to the java-library plugin.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
siordachecommented, May 4, 2020

I’m thinking of integrating the above solution in the Java Modules Plugin. It seems pretty safe and, as @jjohannes mentioned, Gradle 6.4 also performs this setting automatically.

2reactions
siordachecommented, May 4, 2020

I just noticed that @jjohannes also posted a solution, which is most likely the best one:

configurations.compileClasspath.attributes {
   attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, getObjects().named(LibraryElements, LibraryElements.JAR))
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

The Java Library Plugin - Gradle User Manual
You can work around it by manually adding the Jar built for the automatic module to the dependencies of the project that does...
Read more >
java 10 gradle project : automatic module not found
intelliJ can compile the project (using the hammer-like icon) but when I run the compileJava gradle task from intelliJ, I get an error:...
Read more >
Automatic-Module-Name: Calling all Java Library Maintainers
Still, the question remains how you can express a dependency on an automatic module from application modules. Where does its name come from?...
Read more >
Building Modular Java Applications with Gradle - Alex Kudlick
We're going to use a multi project build to build each of the modules within one main project, so the top-level build.gradle will...
Read more >
The Gradle build system- Tutorial - Vogella.com
Gradle supports multi-project and multi-artifact builds. ... It also supports the automatic download of your Java library dependencies.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found