Importing gradle projects results in wrong classpath
Hi,
When I import our gradle multi-project in IntelliJ (IntelliJ IDEA 2019.2.3 (Community Edition), Build #IC-192.6817.14, built on September 24, 2019), the classpath for some of the modules are wrong.
If I look in Project Structure, for the pd.life.life-pdk-shared.test module, I see the following (the 'codegen' configuration is a sourceset, on which 'main' depends):
<orderEntry type="module" module-name="pd.life.life-pdk-shared.main" />
<orderEntry type="module" module-name="pd.life.life-pdk-shared.codegen" />
<orderEntry type="module" module-name="pd.life.life-dk-shared.test" production-on-test="" />
<orderEntry type="module" module-name="pd.life.life-dk-shared.codegen" />
<orderEntry type="module" module-name="pd.life.life-shared.test" production-on-test="" />
<orderEntry type="module" module-name="pd.life.life-shared.codegen" />
<orderEntry type="module" module-name="pd.life.life-core-shared.test" production-on-test="" />
<orderEntry type="module" module-name="pd.life.life-core-shared.codegen" />
<orderEntry type="module" module-name="pd.account.account-shared.test" production-on-test="" />
<orderEntry type="module" module-name="pd.account.account-shared.codegen" />
<orderEntry type="module" module-name="pd.parameters.parameters-shared.test" production-on-test="" />
<orderEntry type="module" module-name="pd.parameters.parameters-shared.codegen" />
<orderEntry type="module" module-name="pd.core.core-shared.test" production-on-test="" />
<orderEntry type="module" module-name="pd.core.core-shared.gen" />
<orderEntry type="module" module-name="pd.core.core-shared.codegen" />
<orderEntry type="module" module-name="pd.core.core-shared.main" />
[SNIP external libraries]
<orderEntry type="module" module-name="pd.core.core-shared.main" />
[SNIP external libraries]
<orderEntry type="module" module-name="pd.parameters.parameters-shared.main" />
<orderEntry type="module" module-name="pd.life.life-core-shared.main" />
<orderEntry type="module" module-name="pd.life.life-dk-shared.main" />
<orderEntry type="module" module-name="pd.account.account-shared.main" />
<orderEntry type="module" module-name="pd.life.life-shared.main" />
<orderEntry type="module" module-name="pd.parameters.parameters-shared.main" />
<orderEntry type="module" module-name="pd.life.life-core-shared.main" />
<orderEntry type="module" module-name="pd.account.account-shared.main" />
<orderEntry type="module" module-name="pd.life.life-shared.main" />
However the corresponding gradle classpath (gradlew :life:life-pdk-shared:dependencies --configuration=tests):
------------------------------------------------------------
Project :life:life-pdk-shared
------------------------------------------------------------
tests
+--- project :life:life-pdk-shared (*)
+--- project :life:life-dk-shared
| +--- project :life:life-dk-shared (*)
| +--- project :life:life-shared
| | +--- project :life:life-shared (*)
| | +--- project :life:life-core-shared
| | | +--- project :life:life-core-shared (*)
| | | +--- project :account:account-shared
| | | | +--- project :account:account-shared (*)
| | | | +--- project :parameters:parameters-shared
| | | | | +--- project :parameters:parameters-shared (*)
| | | | | +--- project :core:core-shared
| | | | | | +--- project :core:core-shared (*)
[SNIP external libraries]
\--- project :life:life-dk-shared (*)
I would have expected the IDEA classpath to better reflect the gradle one e.g.:
<orderEntry type="module" module-name="pd.life.life-pdk-shared.main" />
<orderEntry type="module" module-name="pd.life.life-pdk-shared.codegen" />
<orderEntry type="module" module-name="pd.life.life-dk-shared.test" production-on-test="" />
<orderEntry type="module" module-name="pd.life.life-dk-shared.main" />
<orderEntry type="module" module-name="pd.life.life-dk-shared.codegen" />
<orderEntry type="module" module-name="pd.life.life-shared.test" production-on-test="" />
<orderEntry type="module" module-name="pd.life.life-shared.main" />
<orderEntry type="module" module-name="pd.life.life-shared.codegen" />
<orderEntry type="module" module-name="pd.life.life-core-shared.test" production-on-test="" />
<orderEntry type="module" module-name="pd.life.life-core-shared.main" />
<orderEntry type="module" module-name="pd.life.life-core-shared.codegen" />
<orderEntry type="module" module-name="pd.account.account-shared.test" production-on-test="" />
<orderEntry type="module" module-name="pd.account.account-shared.main" />
<orderEntry type="module" module-name="pd.account.account-shared.codegen" />
<orderEntry type="module" module-name="pd.parameters.parameters-shared.test" production-on-test="" />
<orderEntry type="module" module-name="pd.parameters.parameters-shared.main" />
<orderEntry type="module" module-name="pd.parameters.parameters-shared.codegen" />
<orderEntry type="module" module-name="pd.core.core-shared.test" production-on-test="" />
<orderEntry type="module" module-name="pd.core.core-shared.main" />
<orderEntry type="module" module-name="pd.core.core-shared.codegen" />
<orderEntry type="module" module-name="pd.core.core-shared.gen" />
Is there a way I can control this so when I reimport from gradle I will get the correct classpath? Or at least let me run a task/script that can fix this after the import is finished.
Thanks,
Aske Olsson
Please sign in to leave a comment.
Please clarify what do you mean is wrong exactly? Do you have issues with building/running?
Yeah,
I can build and test fine with IntelliJ through gradle, but when I use the IntelliJ builder (which is nice for tests) I'll get some class/method/symbol not found In the IDE.
In our codebase we have a modelling tool that we use to generate classes, these can be more specialized the further up in the hierarchy the are. The classes can have the same name in the different subprojects, but with different signatures, and here the wrong classpath order causes the method not found in some of the projects. If i manually fix the project order the project builds and tests fine through the IntelliJ builder.
Is there a gradle/intelliJ task I can hook into to fix the iml files after IDEA has imported them? Then I could just manually fix them.
-Aske
Thank you. So the issue is that these ***.main modules
are listed at the very end of the dependencies list of the test module dependencies?
Could you provide relevant snippet of build.gradle files where you declare these dependencies please? Or if possible a sample project to check (For uploading you can use ftp://ftp.intellij.net/.uploads / https://uploads.services.jetbrains.com or any file sharing service) - the files are not accessible from outside of JetBrains.
Please also try 2019.2.4 version from https://www.jetbrains.com/idea/download