2015-10-15 51 views
2

因此,這裏是我的gradle這個腳本:我用gradle構建了一個包含我所有依賴項的胖罐子。現在,當使用distZip時,我該如何排除這些jar文件?

apply plugin: 'java' 
apply plugin: 'application' 

mainClassName = "com.company.diagnostics.app.client.AppMain" 

dependencies { 

    compile ('commons-codec:commons-codec:1.8') 
    compile (libraries.jsonSimple) 
    compile ('org.apache.ant:ant:1.8.2') 

    compile project(":app-common") 

    testCompile 'org.powermock:powermock-mockito-release-full:1.6.2' 

} 

jar { 

    archiveName = "app-client.jar" 

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

     configurations.compile.collect { 
      it.isDirectory() ? it : zipTree(it) 
     } 
    } 

    manifest { 
     attributes 'Main-Class': 'com.company.diagnostics.app.client.AppMain"' 
    } 

    exclude 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA', 'META-INF/*.MF' 
} 

當這個版本,它產生可分配拉鍊,看起來像這樣:

macbook-pro:distributions awt$ tree 
. 
├── app-client 
│   ├── bin 
│   │   ├── app-client 
│   │   └── app-client.bat 
│   └── lib 
│    ├── ant-1.8.2.jar 
│    ├── ant-launcher-1.8.2.jar 
│    ├── commons-codec-1.8.jar 
│    ├── app-client.jar 
│    ├── app-common.jar 
│    ├── guava-17.0.jar 
│    ├── jetty-2.0.100.v20110502.jar 
│    ├── json-simple-1.1.2.jar 
│    ├── osgi-3.7.2.v20120110.jar 
│    ├── services-3.3.0.v20110513.jar 
│    └── servlet-1.1.200.v20110502.jar 
└── app-client.zip 

因爲我已經捆綁的依賴與JAR檔案我自己的定製jar任務,我該如何防止distZip第二次捆綁這些jar文件?

- ant-1.8.2.jar 
- ant-launcher-1.8.2.jar 
- commons-codec-1.8.jar 
- guava-17.0.jar 
- jetty-2.0.100.v20110502.jar 
- json-simple-1.1.2.jar 
- osgi-3.7.2.v20120110.jar 
- services-3.3.0.v20110513.jar 
- servlet-1.1.200.v20110502.jar 

將它們捆綁到jar任務中的原因是,它原本是爲了獨立庫。後來,它決定它應該有一個命令行界面(因此,分區和自動創建的Linux/Mac/Windows的包裝腳本)。它仍然需要作爲獨立的fatjar存在,並將所有的依賴關係捆綁在一起。我只是不需要在/ libs中添加這個額外的東西。

我怎樣才能得到distZip排除他們?

+0

你在混合兩個插件。準備一個可運行的胖罐子或使用分配插件 - 這是它的工作原理。 – Opal

回答

3

您可以通過修改distZip任務,排除您不希望在分發存檔庫,如:

distZip { 
    exclude 'ant-1.8.2.jar' 
    exclude 'ant-launcher-1.8.2.jar' 
    exclude 'commons-codec-1.8.jar' 
    exclude 'guava-17.0.jar' 
    exclude 'jetty-2.0.100.v20110502.jar' 
    exclude 'json-simple-1.1.2.jar' 
    exclude 'osgi-3.7.2.v20120110.jar' 
    exclude 'services-3.3.0.v20110513.jar' 
    exclude 'servlet-1.1.200.v20110502.jar' 
} 

或可能是通過applicationDistribution,這對於整個應用程序插件提供的配置:

applicationDistribution.with { 
    exclude 'ant-1.8.2.jar' 
    exclude 'ant-launcher-1.8.2.jar' 
    exclude 'commons-codec-1.8.jar' 
    exclude 'guava-17.0.jar' 
    exclude 'jetty-2.0.100.v20110502.jar' 
    exclude 'json-simple-1.1.2.jar' 
    exclude 'osgi-3.7.2.v20120110.jar' 
    exclude 'services-3.3.0.v20110513.jar' 
    exclude 'servlet-1.1.200.v20110502.jar' 
} 

你可以嘗試改變excludeinclude使較短的文件列表,或嘗試綁定到排除的依賴列表可能。

+0

applicationDistribution.with正是我所需要的。 – AWT