繁体   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