gradlex-org/extra-java-module-info

Empty jars created when Intellij refreshes project

kpagratis opened this issue · 6 comments

empty-jars.zip

When refreshing the attached gradle project, the plugin causes empty jars to be created.
Commenting out extra-java-module-info and re-refreshing intellij after a gradle clean results in no empty jars.

This is causing issues when using quarkus (I'll be creating an issue there as well) when it attempts to build and encounters a 0 byte jar.

I see this empty jar was added in #15. And this does cause issues with quarkus when it runs quarkusGenerateCode task. You get an error like

Failed to read /somepath/build/libs/some-test-fixtures.jar

Thank you for reporting this.

I also noticed another issue with this "hack" recently (I think). If the "hacky" code is triggered, because a transform runs early, it may create the Jar. But then there can be another instance of the transform running afterwards (e.g. in another subproject) that then finds the empty Jar and thinks it is legit. Then it proceeds with the other checks and, depending on how the plugin is configured, may fail with a "the Jar is not a module error".

I think I would prefer to remove this hack again (revert #15). I think IntelliJ should not tigger this problem anymore for "standard" project setups. I'll have a look at the reproducer to see why it happens in this case. This may be an issue with the Quarkus/Gradle integration. Something similar to this problem with the shadow plugin: GradleUp/shadow#882.

We could also improve/extend the "hack" somehow. But this feels wrong and it may be a deep rabbit hole....

The issue that the transform (sometimes?) runs during the IDEA Sync (before Jar files are created) still exists. I am not sure if it is the case for all projects, but it is in this reproducer and it looks like a very general code path to me. So that's a problem with how transforms are triggered in the Gradle/IDEA integrations itself.

The change for #15 had two parts:

  1. If the file does not exist, do not proceed - this alone should cater for the IDEA Sync issue
  2. The reproducer in #15 used the org.springframework.boot plugin. Once I fixed (1) I saw that the plugin triggered a follow up error. So I added the code to create the empty Jar, which is the hacky bit. At that point I thought that there are probably more plugins (or build configurations) that may cause this situation.

I looked again at the original reproducer from #15 and reproduced the problem from back then. Then I updated the org.springframework.boot to the latest version - 3.1.5 (including updating Java version and Gradle as required).

After that, problem (2) was gone.

What I will do is keep the check if the files exists (1) but remove creation of the empty Jar (2). With this change, the reproducer here does not have the Quarkus issue anymore.

Thanks @jjohannes! Any idea on when a new release with this will be available?

This is now released in 1.6.

Today I discovered this issue in Gradle: gradle/gradle#27372

Which you may hit if you combine this plugins with other plugins that uses the Configuration.getElements() functionality.

In some cases, it is fine to disable this plugins functionality for certain "special" configurations:
https://github.com/gradlex-org/extra-java-module-info#how-do-i-deactivate-the-plugin-functionality-for-a-certain-classpath