How do I reference a dependency's artifact?


(davihay) #1

Hi,

New to Gradle…

I have a task that relies on another project, let’s say project1, which produces a war file as its artifact.

In another project, I add project 1 as a dependency, using:

dependencies {

application project(’:project1’) }

In this other project, I need to call an exe, passing the name of the project1’s war file.

I thought I could use configurations.application.artifacts, but it is empty.

What am I missing?

thanks!


#2

Using configuration.application.artifacts will only provide you with the declared artifacts of that configuration. What you want are the actual artifacts of the resolved configuration, which is accessed via configuration.application.files or by configuration.application itself:

task show << {
    configurations.application.each {
        println it
    }
}

(davihay) #3

Hi Daz,

Thanks for the reply…

Doesn’t seem to work quite as I need it to - your code snippet gives me the project1 jar, however I need the war.

In project1, I have the artifacts declared using:

artifacts {

runtime createProject1War }

Any idea how to get the war?

thanks!


(davihay) #4

Anyone?


#5

Looks like you’re hitting GRADLE-1912. Try this:

// In project2
dependencies {
    application project(path: ':war-project', configuration: 'archives')
}
// The war file is then the only element of the FileCollection
configurations.application

(davihay) #6

hmmmm - any idea when that bug might be fixed?

Unfortunately, the workaround didn’t help. This is what I did:

dependencies {

compile project(’:platform:project1’)

application project(path: ‘:platform:project1’, configuration: ‘archives’) }

then in my task:

configurations.application.files.each {

println it

}

I still only get the jar file…

Thoughts?