Java Gradle:如何使用java-plugin jar任务包含外部jar?

时间:2012-09-04 12:57:42

标签: java build gradle dependency-management

apply plugin: 'java'

archivesBaseName = 'foo-client'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
//version = '1.0'
dependencies{
    compile 'foo:bar:1.0-SNAPSHOT', 
            'foo:bar-common:1.0-SNAPSHOT', 
            'foo:bar-communication-api:1.0-SNAPSHOT'
}
repositories{ 
    flatDir{
        dirs '/lib'
    }
}

执行继承的jar任务时,这将在项目的foo-client.jar目录中创建build/lib。我需要做的是包含几个放在同一目录中的jar,否则项目将无法正常运行。

我该怎么做?

2 个答案:

答案 0 :(得分:0)

您可以将外部jar定义为运行时依赖项,然后使用复制任务将它们复制到build / lib,例如:

task copyLibs(type: Copy) {
    from configurations.runtime
    into "$buildDir/libs"
}

答案 1 :(得分:0)

使用Gradle 1.1以下功能,

apply plugin: 'java'

archivesBaseName = 'foo-client'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

task copyToLib(type: Copy){
    into 'bar\\lib'
    from configurations.runtime
    from configurations.default.allArtifacts.getFiles()
}

dependencies{
    compile 'foo:bar-agent-dist:2.0.0-SNAPSHOT', 
            'foo:bar-common:2.0.0-SNAPSHOT', 
            'foo:bar-communication-api:2.0.0-SNAPSHOT'
}


repositories{ 
    flatDir{
        dirs '/lib'
    }
}