user3400841 user3400841 - 4 months ago 32
Java Question

How to add Idea module to dependencies for gradle

I've a gradle module called "Service" and module called ProtocolLibrary, generated by Idea. How can I add library module to my main module?

I have tryed to simply add source dir to project:

main {
java.srcDirs = ['src/main/java', '../ProtocolLibrary/src']
resources.srcDirs = ['src/main/resources']

But it doen't work:

Error:Can't register given path of type 'SOURCE' because it's out of content root.


If you wish to combine two separate gradle projects together, then you should look at gradle multi-project builds. You will need to create a root project, which will include both your modules as subprojects and in that case, you can simply use one project as the dependency of another, like:

//service project dependencies
dependencies {
    compile project(':ProtocolLibrary')

After doing this, there is no reason to include sources from one project into another.

The second approach is to use the artifact, generated by ProtocolLibrary. You can make a dependency in Service project specifying the jar in filesystem, or your ProtocolLibrary could be published in your maven repo and be used as usual dependency.