我有以下多项目Gradle构建:
myapp/
myapp-client/
build.gradle
src/** (omitted for brevity)
myapp-shared/
build.gradle
src/** (omitted for brevity)
myapp-server
build.gradle
src/** (omitted for brevity)
build.gradle
settings.gradle
myapp/build.gradle
的样子:
subprojects {
apply plugin: 'groovy'
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
repositories {
mavenCentral()
maven {
// My local/private Artifactory
url "http://localhost:8081/artifactory/myapp-snapshots"
}
}
dependencies {
compile (
'org.codehaus.groovy:groovy-all:2.3.7'
)
}
}
目前,3个子项目Gradle文件中的每一个都非常简单:
dependencies {
compile (
'org.apache.commons:commons-lang3:3.3.2'
)
}
这是我想要实现的目标:
gradle clean build -Pversion=0.1.5
目录运行myapp
时,我希望所有三个子项目都以0.1.5的版本构建;因此myapp-client-0.1.5.jar
,myapp-shared-0.1.5.jar
和myapp-server-0.1.5.jar
。目前我的版本已经这样做了,但是...... 我能够找到并测试/确认将Gradle构建的JAR发布到Artifactory的最紧凑的代码是:
buildscript {
repositories {
maven {
url 'http://localhost:8081/artifactory/plugins-release'
credentials {
username = "admin"
password = "12345"
}
name = "maven-main-cache"
}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1"
}
}
apply plugin: 'maven-publish'
apply plugin: "com.jfrog.artifactory"
repositories {
add buildscript.repositories.getByName("maven-main-cache")
maven {
url "http://localhost:8081/artifactory/myapp-snapshots"
}
}
artifactory {
contextUrl = "http://localhost:8081/artifactory"
publish {
repository {
repoKey = 'myapp-snapshots'
username = "admin"
password = "12345"
maven = true
}
defaults {
publications ('mavenJava')
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
当我在测试build.gradle
项目中使用此代码段并运行gradle artifactoryPublish
时,它会正确地将我的JAR发布到Artifactory。
我的问题:如何将此代码段添加到我的项目中,以便从父目录运行gradle clean build
,成功时,会生成发布到Artifactory的客户端和共享JAR?
虽然不理想,如果不可能一下子做到这一切,我会愿意让出版单独,第二步。有什么想法吗?
答案 0 :(得分:3)
使用artifactory
插件是正确的方法。
您需要将其应用于allprojects
并使用artifactoryPublish.skip=true
禁用顶级项目上的部署。
您可以找到与您的here非常相似的项目的完整工作示例。
默认情况下,build
不依赖于artifactoryPublish
,因此您需要运行gradle build artifactoryPublish
来上传jar。原因是您可能希望运行大量构建,直到您决定上传某些内容。您可以通过将build
配置为取决于artifactoryPublish
:
build(dependsOn: 'artifactoryPublish')