Gradle如何构建具有不同依赖关系的Jar的多个版本 [英] Gradle How to build several versions of a jar with different dependencies

查看:262
本文介绍了Gradle如何构建具有不同依赖关系的Jar的多个版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果以前有人尝试解决过类似的问题,请分享您的解决方案.在我的gradle文件中,我有不同的子项目.到目前为止,我已经可以使用core构建rest-client了,但是可能还有应该使用db-client子项目来构建rest-client的情况.基本上,我的想法是我需要能够构建具有不同依赖关系的rest-client.假设一个任务建立了依赖于一个项目的rest-client,而另一个任务建立了依赖于两个子项目的rest-client.

If somebody tried to solve similar problem before, please share your solution. In my gradle file I have different subproject. As of right now I am able to build rest-client with core, but there could be situation when rest-client should be also be build with db-client subproject. Basically the idea is I need to be able to build rest-client with different dependency. Let say one task builds rest-client with dependency to one project and another task build rest-client with dependency on two subproject.

project(':core') {
    apply plugin: "groovy"
    repositories {
        mavenCentral()
    }
    dependencies {
        compile 'org.codehaus.groovy:groovy-all:2.4.5'
        testCompile "org.testng:testng:6.8.21"
    }
}

//rest-client Project specific stuff
project(':rest-client') {
    apply plugin: "groovy"
    repositories {
        mavenCentral()
    }

    dependencies {
        compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'
        compile project(':core')
        compile 'org.codehaus.groovy:groovy-all:2.4.5'
        testCompile "org.testng:testng:6.8.21"

    }
    jar {
        from configurations.runtime
    }
}

//db-client Project specific stuff
project(':db-client') {
    apply plugin: "groovy"
    repositories {
        mavenCentral()
    }
    dependencies {
        compile project(':core')
        compile 'org.codehaus.groovy:groovy-all:2.4.5'
        compile 'mysql:mysql-connector-java:5.1.37'
        //compile 'org.elasticsearch:elasticsearch:2.3.1'
        compile 'org.elasticsearch:elasticsearch-client-groovy:0.10.0'
    }
}

推荐答案

很抱歉,您的回复很晚,如果您仍然需要这样的示例,请参见以下示例.

Sorry for the late response, if you still need something like this here is an example.

apply plugin: "groovy"

repositories {
  mavenCentral()
}

configurations {
  projectDep
  libraryDep
}

project('core') {
  apply plugin: "java"

}

dependencies {
  projectDep project(':core')
  libraryDep 'my.project:project:0.1.0'

  compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'
  compile 'org.codehaus.groovy:groovy-all:2.4.5'
  testCompile "org.testng:testng:6.8.21"
}

jar {
  from configurations.libraryDep
}

task projectJar(type: Jar) {
  appendix = 'project'
  from sourceSets.main.output, configurations.projectDep, configurations.runtime
}

那么您有2个jar任务. jar会从compile,runtime和libraryDep中获取所有已声明的依赖项,而projectJar会从compile,runtime和projectDep中获取.

You have then 2 jar tasks. The jar takes all declared dependencies from compile,runtime and libraryDep and the projectJar takes compile,runtime and projectDep.

希望这会有所帮助.

这篇关于Gradle如何构建具有不同依赖关系的Jar的多个版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆