I'm using Gradle to help automate Hadoop tasks. When calling Hadoop, I need to be able to pass it the path to some jars that my code depends on so that Hadoop can send that dependency on during the map/reduce phase.
I've figured out something that works, but it feels messy and I'm wondering if there's a feature I'm missing somewhere.
This is a simplified version of my gradle script that has a dependency on the solr 3.5.0 jar, and a findSolrJar
task that iterates through all of the jar files in the configuration to find the right one:
apply plugin: 'groovy' repositories { mavenCentral() } dependencies { compile 'org.apache.solr:solr-solrj:3.5.0' } task findSolrJar() { println project.configurations.compile*.toURI().find { URI uri -> new File(uri).name == 'solr-solrj-3.5.0.jar'} }
running this gives me output like this:
gradle findSolrJar file:/Users/tnaleid/.gradle/caches/artifacts-8/filestore/org.apache.solr/solr-solrj/3.5.0/jar/74cd28347239b64fcfc8c67c540d7a7179c926de/solr-solrj-3.5.0.jar :findSolrJar UP-TO-DATE BUILD SUCCESSFUL Total time: 2.248 secs
Is there a better way to do this?
Generally, you can refresh dependencies in your cache with the command line option --refresh-dependencies. You can also delete the cached files under ~/. gradle/caches . With the next build Gradle would attempt to download them again.
The Jar is created under the $project/build/libs/ folder.
Gradle caches artifacts in USER_HOME/. gradle folder. The compiled scripts are usually in the . gradle folder in your project folder.
Right click the module > Open module settings > Artifacts > + > JAR > from modules with dependencies. Set the main class.
Your code can be simplified a bit, for example project.configurations.compile.find { it.name.startsWith("solr-solrj-") }
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With