簡體   English   中英

想要從Gradle脂肪罐中取出特定的罐子

[英]Want to remove specific jars from Gradle fat jar

我當前的build.gradle如下所示。

repositories {
    flatDir {
       dirs 'lib'
   }
   maven {      
    mavenCentral()
  }

 dependencies {    

  compile "commons-logging:commons-logging:1.0.4", 
          "org.apache.httpcomponents:httpclient:4.4",
          "org.apache.httpcomponents:httpcore:4.4",
          "com.fasterxml.jackson.core:jackson-annotations:2.5.1",             
          "joda-time:joda-time:2.7",


  compile files('../lib/abc.jar')
 }

 jar {
    manifest{
        attributes ("Version" : project.version, "${parent.manifestSectionName}")
        attributes ("Name" : project.name, "${parent.manifestSectionName}")     
    }

    from {
          configurations.runtime.filter( {! (it.name =~ /abc.*\.jar/ )}).collect {
             it.isDirectory() ? it : zipTree(it)
         }
    }
  }  

所以你可以看到我在運行時刪除了abc.jar,但同樣的方法我想刪除更多的jar。 總之,我想在胖罐里面放幾個罐子,需要排除少量。 那么我怎樣才能實現呢?

以下示例可能對您有所幫助。 您需要添加新配置 - 它默認擴展編譯,因此它將在開發期間可用,但不會包含在生成的jar中 - 如下例中的joda所示。

apply plugin: 'java'

repositories {
  mavenCentral()
}

configurations {
  lol
}

dependencies {    

  compile "commons-logging:commons-logging:1.0.4", 
          "org.apache.httpcomponents:httpclient:4.4",
          "org.apache.httpcomponents:httpcore:4.4",
          "com.fasterxml.jackson.core:jackson-annotations:2.5.1"

  lol "joda-time:joda-time:2.7"
}

jar {
  from {
    configurations.runtime.collect {
      it.isDirectory() ? it : zipTree(it)
    }
  }
}  

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM