Gradle Dependency Ordering Is Wrong
已回答
I am using 2018.3.1 community and I am having problems with order of the dependencies of the iml files when using Gradle.
My dependency setup is a bit weird.
I have sets of non-maven dependencies from a third-party vendor in artifactory and am extracting them locally using org.jfrog.buildinfo:build-info-extractor-gradle then reference them using in the dependency block with fileTree.
I wrote a small task to check what gradle thinks the classpath should be
task classpath(){
doFirst{
sourceSets.main.runtimeClasspath.each { println it}
}
}
and it seems fine.
However, when I sync gradle with IDEA the order doesn't match.
Is there anything I can do to force the iml to match the order in gradle?
请先登录再写评论。
How do you know the order is wrong? Could you add some details about the expected and the actual result?
Please also try the IDE version from https://www.jetbrains.com/idea/download it has related changes.
Please note that if you switch to Gradle runner for Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Gradle | Build and run using there should be no differences between command line Gradle execution/compilation and IDE's.
If issue remains is it possible to have a sample project? Thanks.
I know the order is wrong because the task I put in the original message prints out the classpath and what is in the iml file or the project doesn't match it!
I'll have to find some time to replicate this with open source components as I can't share the current project.
As a side note: I don't know where this push to use gradle as the runner has come from. I have started to see it more and more recently.
The gradle runner is slower and less flexible than IDEA, especially in non-trivial projects.
e.g. the gradle up to date checks don't seem to be always as up to date as the IDEA cache and running a single test method in a test class doesn't seem to work
The Gradle build may indeed be slower that IDE's. But it is not possible in IDE to support all the possible configurations of the Gradle given it's flexibility in terms of configuring the build logic. Delegate build/run to Gradle mode gives the same experience and result as you would get if build from command line Gradle.
For successful investigation and fixing the issue a sample project would be very much appreciated.
Surely all you need to do to get the classpath right is use something similar to the example I pasted above then convert the output to an iml file.
Also, using gradle as a test runner fails when trying to run individual test methods rather than all the tests in a class.
I am now creating a sourceset for each resource directory that I have.
I then add it to the compile dependency e.g.
You'd think that because I defined the "thirdparty" source set first in the list of dependencies that it would be first in the classpath.
When I run the classpath task I mention above that is exactly what happens.
However, when I run from IDEA using the gradle runner or if I look in the module setup what I actually see is the sourceSets being added as dependencies in alphabetical order!
I tested renaming the sourcesets and this is definitely what is happening.
If I add the idea plugin to gradle and run ./gradlew idea the iml that is generated has the correct classpath.
It is only when the project is imported as a gradle project that IIDEA messes up the ordering
Thank you for details. I've reproduced it. Please follow the https://youtrack.jetbrains.com/issue/IDEA-242532 for further information from the developers.