Resolve Workspace Artifacts with GRADLE plugin (in the same way maven is supported)

Hello,

 

I am currently working on a multi project/module product that uses the dependency management to linked them (Group, Artifact and Version) - GAV.  Similar to the posts back before this was supported for poms with maven, I really need the same support for gradle.   

Workarounds at the moment include:

1. Building a gradle task that constructs the corresponding pom.xml.  I enable the 'resolve workspace artifacts' feature for maven (the feature added for maven ONLY).  This works pretty well but leaves much to be desired as some addition work that is done in the gradle scripts cannot be translated into the pom.xml... so it isn't prefect.

2. Go back to publishing the artifact to maven local repo (~/.m2), and the module that depends on it just has to pull it from there.  This is a productivity killer as it was put in another support thread.  I am arguing the exact same reasons/rationale for the introduction of this feature for maven, just for gradle support.

Any help that could be provided would be appreciated!

Thanks!

 

7 comments
Comment actions Permalink

Gradle has significantly more complex publication model than Maven and until recently that was too difficult.

The good news is that Gradle 2.13 has added the Composite Builds future, which addresses this problem.

The bad news its that IDEA does not support it yet, and you would need to upgrade your Gradle version to at least 2.13

 

Vote here: https://youtrack.jetbrains.com/issue/IDEA-114469 

0
Comment actions Permalink

Dimitar,

 

Thanks for the reply.  I don't know how composite build addresses the issue. Right now I can use gradle in eclipse with the STS plugin and get the same functionality as I have with maven.  The issue isn't gradle not being able to support this, but the support on the Intellij IDE.

Basically I have 120 modules that publish there content with a GAV, which I want to see as a local module when they are both in the same project in IDEA... When I close the modules, IDEA should start pulling from the jar in the local maven repo instead of the local module.  This is exactly how it behaves in the followign:

 

  • Maven with Eclipse (Supported via the m2e plugin)
  • Maven with Intellij (Supported via the mapping artifacts to projects option)
  • Gradle with Eclipse (Supported with STS gradle plugin)
  • Grade with Intellij (Not supported)

 

Thanks for the info.  I am not sure how composite projects changes anything for me.  If I want to use gradle and this feature, I can always use eclipse as it is supported there.  The thing is, I am trying to stay with Intellij as this company uses it company wide.  Any chance we could see a feature or fix for this?

0
Comment actions Permalink

Hi Brad,

As you may know, a single Gradle project may publish multiple artifacts with different GAV coordinates, all of them different than the project GAV. Any assumptions are relying on convention and subject to override, hence the substitution of an artifact dependency with a full project dependency is technically incorrect.

Nevertheless, this is what we are currently doing it in my company (using a custom plugin), but we've also seen the cases where it messes up.

The composite builds feature in gradle resolve dependencies by substituting them with individual publications and that is supposed to be the real solution to this problem.

Not sure how this can ne modelled in idea though.

0
Comment actions Permalink

BTW, I don't speak on behalf of Jetbrains and I don't work for them.

0
Comment actions Permalink

Dimitar,

 

Thanks for the time.  Technically you are correct in that a single project can have multiple artifacts.  In my case the projects are modeled after the Java model, i.e. single Jar.  I just read some more on the composite build stuff, and it appears this will address the gap in Buildship plugin in Eclipse ... which is precisely what STS already does in Eclipse with Gradle <2.13 :) Nevertheless, Buildship is the future so I am happy I can use that instead :) 

Now back to Intellij problem, are you at liberty to provide the source code of your custom plugin?  I would love to see if we can adopt it.  Basically I want the plugin to work like buildship does in eclipse for gradle builds :) 

 

Thanks in advance!

0
Comment actions Permalink

Hi Brad,

Sharing any code is a bit difficult, but I can point you to publicly available code.

 

This example captures the idea: 

https://docs.gradle.org/current/userguide/dependency_management.html#sec:conditional_dependency_substitution 

 

See also here for more API options:

https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.DependencySubstitutions.html#org.gradle.api.artifacts.DependencySubstitutions:substitute(org.gradle.api.artifacts.component.ComponentSelector)

 

What we have done on top of that is to create an init-script plugin (attached to the Gradle object) that can automatically assemble the project from multiple repos - we use it in our settings.gradle. We also have some properties to tweak the linking process.

If you have any more questions on how to do it, you may ask in the Gradle forums.

1
Comment actions Permalink

I've the exact same issue which I describe in detail in this SO post. I'm not sure what good is the conditional dependency substitution because it seems to only work within subprojects, not lib dependencies.
If there's a way to find all the projects in the current workspace, then the dependency can be substituted. Of course, this only works for a simplistic scenario because a project with the same name may not be the right version.

0

Please sign in to leave a comment.