Romain Deltour wrote:
Hi,

I need to use a java instrumentation agent in my JUnit 4 tests to enable
Spring load-time weaving.

So far, I've tried to declare the agent library as an external dependency,
and then refer explicitly to the cache path in the test task:

test {
     options.fork(jvmArgs:
["-javaagent:"+System.getProperty('user.home')+"/.gradle/cache/org.springframework/spring-agent/jars/spring-agent-2.5.6.jar"])
}

Is there a better way to get the dependency path in the cache ? for instance
can we get a File object from a resolved external dependency ?


You can get them as a Set:

Set<File> agentFiles = configurations.runtime.files { it.name == 'spring-agent' }

I think I would use a custom configuration for this:

configurations {
   springAgent
}

dependencies {
   springAgent name: 'spring-agent', version: ...
}

test {
options.fork(jvmArgs: ["-javaagent:$configurations.springAgent.singleFile"])
}

There's a few more options for getting the files for a dependency. Have a look at the Javadoc for Configuration: http://gradle.org/0.7/docs/javadoc/org/gradle/api/artifacts/Configuration.html

In this case, does it make sense to declare the dependency in the "runtime"
configuration or would it be better to use a custom configuration ?

Or would you advise me to not use a dependency but instead commit the agent
in the project directory in the VCS ?

I'm very new to Gradle and totally unexperienced in Groovy, please share
your experience ! ;)

Thanks,
Romain.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply via email to