Gradle - 使用不同版本的依赖项创建多个jar

时间:2015-11-13 19:42:00

标签: grails gradle jar build artifactory

我需要为grails3插件创建两个带有不同版本的自定义库的jar文件,并将这些文件发布到远程maven repo(artifactory)。 以下是构建文件的示例:

buildscript {
    ext {
        grailsVersion = project.grailsVersion
    }
    repositories {
        jcenter()
        mavenLocal()
        maven { url "https://repo.grails.org/grails/core" }
    }
    dependencies {
        classpath "org.grails:grails-gradle-plugin:$grailsVersion"
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.2"
    }
}

plugins {
    id "io.spring.dependency-management" version "0.5.2.RELEASE"
    id "com.jfrog.bintray" version "1.2"
}

version "0.1.0-SNAPSHOT"
group "org.grails.plugins"

apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: "com.jfrog.artifactory"
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: "spring-boot"
apply plugin: "org.grails.grails-plugin"
apply plugin: "org.grails.grails-gsp"

ext {
    grailsVersion = project.grailsVersion
    gradleWrapperVersion = project.gradleWrapperVersion
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenLocal()
    mavenCentral()
    maven { url "https://repo.grails.org/grails/core" }
    maven { url "${artifactory_contextUrl}"
        credentials {
            username "${artifactory_user}"
            password "${artifactory_password}"
        }
    }
}

dependencyManagement {
    imports {
        mavenBom "org.grails:grails-bom:$grailsVersion"
    }
    applyMavenExclusions false
}

dependencies {
    provided 'org.springframework.boot:spring-boot-starter-logging'
    provided "org.springframework.boot:spring-boot-starter-actuator"
    provided "org.springframework.boot:spring-boot-autoconfigure"
    provided "org.springframework.boot:spring-boot-starter-tomcat"

    provided "org.grails:grails-web-boot"
    provided "org.grails:grails-dependencies"
    provided 'javax.servlet:javax.servlet-api:3.1.0'

    testCompile "org.grails:grails-plugin-testing"

    console "org.grails:grails-console"

    //TODO build two jars with different versions of this dependency
    compile "com.mycompany.custom-lib:x.x.x-SNAPSHOT"

}

task wrapper(type: Wrapper) {
    gradleVersion = gradleWrapperVersion
}


publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }
}


artifactory {
    contextUrl = artifactoryContextUrl

    publish {
        defaults {
            publications('mavenJava')
            maven = true
        }
        repository {
            repoKey = project.version.endsWith('-SNAPSHOT') ? snapshotRepoKey : releaseRepoKey
            username = "${artifactory_user}"
            password = "${artifactory_password}"
        }
    }

}

作为gradle artifactoryPublish命令的结果,我想在build / libs中有两个jar文件:

myplugin-0.1.0-X-SNAPSHOT.jar - 使用lib com.mycompany.custom-lib:1.0.2-SNAPSHOT

myplugin-0.1.0-Y-SNAPSHOT.jar - 使用lib com.mycompany.custom-lib:2.0.2-SNAPSHOT

此外,我希望它们都被发布为神器。

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:0)

由于您要上传mavenJava出版物,您只需将生成其他jar文件的任务添加到from的{​​{1}}列表中。< / p>