Reputation: 5049
Backstory:
In eclipse, when you have multiple projects open with pom files (and therefore versions), it will automatically use local-references if the versions match one of your listed dependencies. If they don't match, then it relies on the artifact in the repo. (this is handy as it allows you to do live-edits/linking on active versions, while having fixed dependencies on unstable project/dependency versions).
Question
In gradle, there doesn't seem to be a way to say
I depend on this sub-module, version X
Rather, it seems you are only able to say
I depend on this sub-module, I don't care which version, I'll take the current/active one.
So, is there a better syntax to the regular:
compile project(':submodules:submodule1')
Perhaps something like?:
compile project(':submodules:submodule1:0.1-SNAPSHOT')
or
compile project('com.mydomain:submodule1:0.1-SNAPSHOT')
Upvotes: 4
Views: 170
Reputation: 2763
Perhaps you do not want to use project references if you need to depend on a particular version. The project reference says basically what you mentioned in your question. More exactly it is not "I don't care which version" but rather something like "I depend on this subproject - in the version/state it is just now". This is what the project references are for - declaring a dependency on another project, not a particular JAR/version.
If you need to depend on a particular version, you should declare it without the project dependency, such as:
compile('com.mygroupid:submodule1:0.1-SNAPSHOT')
which is a shortened version of
compile(group:'com.mygroupid', name:'submodule1', version:'0.1-SNAPSHOT')
By default, this will use an artifact from a repo. But there is a solution that may bring you closer to what you want. The eclipse-integration-gradle plugin can detect such dependencies and replace them with project dependencies for Eclipse. The option is called "Remap Jars to Gradle Projects".
As a result, if there is a target project in your Eclipse workspace whose name corresponds to the target module, such Eclipse project will be used instead of the repo JAR.
I am not sure whether this is possible with multiple versions of the same project in the same workspace (if this is what you needed).
Upvotes: 2