Cleanest way in Gradle to get the path to a jar file in the gradle dependency cache

前端 未结 5 549
难免孤独
难免孤独 2021-02-05 00:36

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 de

5条回答
  •  太阳男子
    2021-02-05 01:29

    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
    }
    

提交回复
热议问题