Gradle eclipse dependencies for attached artifacts

(Christopher Cooper) #1

I have a multi-project gradle build where I am generating API documentation using enunciate. One of the nice things about this is they generate a client jar containing our dto’s called ‘json-client.jar’. I have attached this artifact to the project (referred to as api) which generated it and am able to successfully add a dependency to it from another project (referred to as api-tests) which will use this to test our API.

This is where my problem lies, and I’m not sure if it is a problem with gradle or a problem with the STS/eclipse gradle plugin. When I import the api-tests project into eclipse, all I get is a project build classpath reference to the api project which generates this jar, and not the jar itself. I would like to just have a classpath reference to the jar, because the api project doesn’t have any real java source. I should note, there is no problem running my api-tests project from the command line (I do not get any compilation errors for unresolved references.)

Is there any way I can rectify this? Either by processing the eclipse classpath file in my build.gradle or something else? I have tried processing the eclipse classpath already, but it did not work:

eclipse {
    classpath {
        file {
            withXml {
                def node = it.asNode()
                                  node.appendNode('classpathentry', [kind: "lib", path: "/rest-api/build/docs/build/java-client/json-client.jar"])

API build.gradle snippets:

project.ext.docsBuildDir = new File(project.buildDir, "docs/build")
project.ext.jsonClientJar = new File(docsBuildDir, "java-client/json-client.jar")
  artifacts {
    jsonClient(jsonClientJar) {
        name 'json-client'
        type 'jar'
        builtBy enunciate

I declare the dependency as such in api-tests

dependencies {
    compile project(path: ":docs:rest-api", configuration: "jsonClient")

I am using gradle 1.10

Thank you for any help/information.

(Luke Daley) #2

Try disabling the dependency management feature of the STS plugin. This will fallback to generating .classpath files, then your customisations will take effect.

(Christopher Cooper) #3

That seems to work, the only downside is now anytime I change the build.gradle I need to do a gradle->refresh all

Slightly annoying, but I suppose its an acceptable workaround.

I’m sure this is the intended behavior and that I don’t have a normal use case. Probably most people attaching other artifacts to their projects are built from the same source in the project in some way or another, which is why adding the project reference to the classpath is sufficient.

Is there any way to do this with the STS dependency management in effect? If not I guess i’ll just have to live with this solution.

I basically want the opposite of what this person asked for:


(Luke Daley) #4

Is there any way to do this with the STS dependency management in effect?

Not at the moment.