我有一个使用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插件,以便:
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插件)以接受我从命令行指定的版本?
答案 0 :(得分:3)
此处的问题数量:
buildscript
应该是顶级阻止,而不是allprojects
mavenCentral()
)artifactoryPublish
,则需要配置Artifactory插件。 Here are the docs以下是多模块Gradle项目的两个完整工作示例:1和2。一些亮点:
maven
或maven-publish
插件。configuration
或publication
。configuration
或publication
。