简体   繁体   English

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

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

My current build.gradle looks like below. 我当前的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)
         }
    }
  }  

So as you can see I have removed abc.jar at runtime, but in the same way I want to remove few more jars. 所以你可以看到我在运行时删除了abc.jar,但同样的方法我想删除更多的jar。 In short I want few jars inside of fat jar and needs to exclude few. 总之,我想在胖罐里面放几个罐子,需要排除少量。 So how can I achieve it? 那么我怎样才能实现呢?

The following example may help you. 以下示例可能对您有所帮助。 You need to add new configuration - it extends compile by default so it will be available during development but will not be included into resulting jar - as joda in the example below. 您需要添加新配置 - 它默认扩展编译,因此它将在开发期间可用,但不会包含在生成的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