想要从Gradle脂肪罐中移除特定的罐

amu*_*ser 5 java gradle

我当前的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)
         }
    }
  }  
Run Code Online (Sandbox Code Playgroud)

如您所见,我已经在运行时删除了abc.jar,但是以同样的方式,我想删除更多的jar。简而言之,我想在肥罐中放几个罐,并且需要排除几个。那么我该如何实现呢?

Opa*_*pal 0

以下示例可能对您有所帮助。您需要添加新配置 - 默认情况下它扩展了编译,因此它将在开发期间可用,但不会包含在生成的 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)
    }
  }
}  
Run Code Online (Sandbox Code Playgroud)