我有以下项目结构(用于Gradle多项目构建):
myproj/
build.gradle
settings.gradle
fizzbuzz-client/
build.gradle
settings.gradle
src/
main/
groovy/
resources/
test/
groovy/
resources/
fizzbuzz-shared/
build.gradle
settings.gradle
src/
main/
groovy/
resources/
test/
groovy/
resources/
fizzbuzz-server/
build.gradle
settings.gradle
src/
main/
groovy/
resources/
test/
groovy/
resources/
myproj/build.gradle
的位置:
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"
}
}
subprojects {
apply plugin: 'groovy'
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
}
myproj/settings.gradle
在哪里:
include ':fizzbuzz-shared'
include ':fizzbuzz-client'
//include ':fizzbuzz-service' Commented out since I have no actual code for this yet
myproj/fizzbuzz-shared/build.gradle
在哪里:
apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: "com.jfrog.artifactory"
version="0.0.31"
group = "mygroup"
repositories {
mavenCentral()
add buildscript.repositories.getByName("maven-main-cache")
maven {
url "http://localhost:8081/artifactory/my-snapshots"
}
}
dependencies {
// All my libs; omitted for brevity
}
artifactory {
contextUrl = "http://localhost:8081/artifactory"
publish {
repository {
repoKey = 'my-snapshots'
username = "admin"
password = "password"
maven = true
}
defaults {
publications ('mavenJava')
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
}
当我导航到myproj
根目录并运行gradle build
时,我得到:
org.gradle.api.GradleScriptException: A problem occurred evaluating project ':fizzbuzz-client'.
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:54)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:177)
<omitted for brevity>
Caused by: org.gradle.api.artifacts.UnknownRepositoryException: Repository with name 'maven-main-cache' not found.
at org.gradle.api.internal.artifacts.DefaultArtifactRepositoryContainer.createNotFoundException(DefaultArtifactRepositoryContainer.java:168)
at org.gradle.api.internal.DefaultNamedDomainObjectCollection.getByName(DefaultNamedDomainObjectCollection.java:192)
at org.gradle.api.internal.artifacts.DefaultArtifactRepositoryContainer.getByName(DefaultArtifactRepositoryContainer.java:41)
at org.gradle.api.artifacts.ArtifactRepositoryContainer$getByName.call(Unknown Source)
我能估算的最好的事情:
build.gradle
文件之一出错了);或gradle build
)。关于我哪里出错的任何想法?
编辑:请注意,在建议的重复问题中,问题是由于用户在CI服务器中配置了Gradle,并且解决方案是在CI服务器内正确配置Gradle。在我的例子中,我在命令行上本地运行Gradle。因此,我认为这不重复。
答案 0 :(得分:1)
你有两个插件在同一时间运行。 一个在您的代码中添加,另一个由CI服务器添加(Jenkins?)。
请确保&#34; Project使用Artifactory Gradle Plugin&#34;运行实际使用artifactory插件的项目时选中复选框。然后我们将跳过在CI服务器中添加插件。
答案 1 :(得分:0)
我最终将我的项目分成了3个小项目:
fizzbuzz-shared
fizzbuzz-client
fizzbuzz-server
这有点让人失望,但这是我能让Artifactory插件与Gradle玩得很好的唯一方法。