【发布时间】:2015-02-27 18:13:11
【问题描述】:
我正在使用 Gradle 构建一个多项目构建:
myapp/
myapp-client/
myapp-shared/
myapp-server/
build.gradle
settings.gradle
settings.gradle 的样子:
include ':myapp-shared'
include ':myapp-client'
include ':myapp-server'
我已成功让 Gradle 编译我的 Groovy 源代码、运行单元测试、生成 GroovyDocs,并为所有 3 个子项目打包二进制和源 JAR。其构建调用为:gradle clean build groovydoc sourcesJar -Pversion=<whatever version I specify>。
我现在正在尝试添加 Gradle-Artifactory 插件,这样:
- 所有 3 个子项目都会为它们生成 POM;和
- 所有 3 个子项目二进制 JAR、POM 和源 JAR 都发布到我在本地运行的 Artifactory;和
-
artifactoryPublish任务在gradle build被调用时执行
这是我最好的尝试(我的完整 build.gradle):
allprojects {
buildscript {
repositories {
maven {
url 'http://localhost:8081/artifactory/plugins-release'
credentials {
username = "admin"
password = "password"
}
name = "maven-main-cache"
}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1"
}
}
apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: "com.jfrog.artifactory"
version="0.0.1"
group = "mygroup"
repositories {
mavenCentral()
add buildscript.repositories.getByName("maven-main-cache")
maven {
url "http://localhost:8081/artifactory/mydev-snapshots"
}
}
artifactory {
contextUrl = "http://localhost:8081/artifactory"
publish {
repository {
repoKey = 'mydev-snapshots'
username = "admin"
password = "password"
maven = true
}
defaults {
publications ('mavenJava')
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
}
rootProject {
artifactoryPublish.skip=true
}
subprojects {
apply plugin: 'groovy'
apply plugin: 'eclipse'
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
repositories {
mavenLocal()
mavenCentral()
maven {
url "https://repository.apache.org/content/repositories/snapshots"
}
maven {
url "http://localhost:8081/artifactory/mydev-snapshots"
}
maven {
url "https://code.google.com/p/guava-libraries/"
}
}
dependencies {
compile (
'org.codehaus.groovy:groovy-all:2.3.7'
)
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
build(dependsOn: 'artifactoryPublish')
}
当我运行gradle clean build groovydoc sourcesJar -Pversion=0.1.1 时,我得到以下命令行异常:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\myuser\sandbox\eclipse\workspace\myapp\build.gradle' line: 14
* What went wrong:
A problem occurred evaluating root project 'myapp'.
> You can't change a configuration which is not in unresolved state!
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 2.589 secs
我的问题:这里发生了什么,我需要做什么(特别是)来修复它并发布 Artifactory 插件?
额外问题:我在 2 个位置指定版本号(构建调用以及 build.gradle 文件内。我想通过构建调用指定版本号仅。如何配置artifactoryPublish(或者更确切地说,Gradle-Artifactory 插件)以接受我从命令行指定的版本?
【问题讨论】:
标签: groovy gradle artifactory