gradlex-org/extra-java-module-info

Error when importing multi-module project in IDEA when using this plugin in combination with 'java-test-fixtures'

Closed this issue · 4 comments

I am using this plugin in a multi-module project.

If I add the 'java-test-fixtures' plugin to certain sub-module (apply plugin: 'java-test-fixtures' ) and then try to load the gradle changes into IntelliJ IDEA I will get the following error:

Could not resolve all dependencies for configuration ':[...]:testRuntimeClasspath'. Failed to transform [...]-test-fixtures.jar (project :[...]) to match attributes {artifactType=jar, javaModule=true, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.jvm.version=11, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}. Execution failed for ExtraModuleInfoTransform: [...]-test-fixtures.jar. java.io.FileNotFoundException: [...]-test-fixtures.jar (No such file or directory)

Running gradle build before loading the changes into IDEA works, but if for some reason the build does not run successfully it is very cumbersome to fix it without having the gradle project properly imported into the IDE.

@michael-spahn I have seen similar problems in the past, but I can't find a related issue on Gradle right now. It's a general problem with how an artifact transform is scheduled and run. So this is most likely not directly related to the code of this plugin (which "just" adds a transform).

It might be an issue with your build or with Gradle (which should at least do better error reporting, if it is a problem in the build). Or something in IntelliJ's importer is not quite right.

Would you be able to share a small reproducer?

@jjohannes

bug-report.zip

I created a minimal example project.

If I import this project into IntelliJ it causes an error like above.
After running ./gradlew clean build (which runs without any errors) the import works fine.

After a ./gradlew clean the import fails again.

It also seems to be related to the spring boot plugin. If I remove it from the above sample project, the import error does not occur.

@michael-spahn thanks for the reproducer. The issue is a bit involved, and cannot really be solved in this plugin. I can change the code to not read the file if it does not exist, but then Gradle itself will fail later. I have added a workaround that creates an empty file if the jar does not yet exist. This should not cause any issues. The real jar will be created later.

The problem is a combination of how the resolving is done when the IDE syncs and the Spring Boot Plugin accessing the real files (because it requires the file name for some reason) early. I had a look if this can be improved in the Spring Boot Plugin by accessing files mot lazily, but I did not find a good solution.

Please try version 0.8 of this plugin and check if that solves the problem for you.

@jjohannes I did some superficial testing and it seems to be working fine now! Thanks :)