我有以下项目结构(打算用于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。因此,我认为这不是重复的。
最佳答案
您有两个同时运行的插件。
一个添加到您的代码中,另一个添加到CI服务器(Jenkins?)中。
运行实际使用人工插件的项目时,请确保选中“项目使用Artifactory Gradle插件”复选框。然后,我们将跳过CI服务器中插件的添加。
关于groovy - Artifactory Gradle插件抛出异常的强制转换异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27315551/