Cleanest way in Gradle to get the path to a jar file in the gradle dependency cache
Your code can be simplified a bit, for example project.configurations.compile.find { it.name.startsWith("solr-solrj-") }
.
You can also create a dedicated configuration for an artifact, to keep it clean; and use asPath
if the fact that it can potentially return several locations works well for your use case (happens if it resolves same jar in several locations):
configurations { solr}dependencies { solr 'org.apache.solr:solr-solrj:3.5.0'}task findSolrJars() { println configurations.solr.asPath}
To avoid copy-paste, in case you as well need that jar in compile
configuration, you may add this dedicated configuration into compile
one, like:
dependencies { solr 'org.apache.solr:solr-solrj:3.5.0' compile configurations.solr.dependencies}
I needed lombok.jar as a java build flag to gwt builds this worked great !
configurations { lombok}dependencies { lombok 'org.projectlombok:lombok+'} ext { lombok = configurations.lombok.asPath}compileGwt { jvmArgs "-javaagent:${lombok}=ECJ"}
I was surprised that the resolution worked early enough in the configuraiton phase, but it does.