2014-12-05 60 views
-1

我有以下項目結構(用於一個搖籃多項目構建):Artifactory的搖籃插件拋出奇怪的轉換異常

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) 

盡我所能估計:

  1. 我的項目配置不正確(東西我的build.gradle文件中有一個錯誤);或
  2. 我沒有使用正確的構建調用(gradle build)。

任何有關我要去哪裏的錯誤的想法?

編輯:請注意,在建議的重複問題中,問題是由於用戶在CI服務器中配置了錯誤的Gradle,並且解決方案是在CI服務器內正確配置Gradle。就我而言,我在命令行上本地運行Gradle。因此我不認爲這是重複的。

+1

看起來你在你的類路徑中有這個類的兩個版本 – 2014-12-05 13:18:17

+0

Thanks @tim_yates(+1) - 但是如果我只聲明'apply plugin:「com.jfrog.artifactory」'one時間? – IAmYourFaja 2014-12-05 13:36:40

+0

[gradle artifactory plugin]可能的重複(http://stackoverflow.com/questions/12446516/gradle-artifactory-plugin) – JBaruch 2014-12-05 14:03:15

回答

0

我結束了剛剛打破我的項目進行到3個小項目:

  • fizzbuzz-shared
  • fizzbuzz-client
  • fizzbuzz-server

這是有點令人失望,但我唯一的出路可以讓Artifactory插件和Gradle一起玩。

1

你有兩個插件同時運行。 一個被添加到你的代碼中,另一個被CI服務器添加(Jenkins?)。

運行實際使用artifactory插件的項目時,請確保選中「項目使用Artifactory Gradle插件」複選框。然後,我們將跳過添加CI服務器中的插件。

+0

謝謝@JBaruch(+1),但你錯了!這是我的機器上運行localllyy的代碼,沒有任何CI服務器!只需要直接使用Gradle命令行即可! – IAmYourFaja 2014-12-05 14:24:48

+0

通過「Artifactory Gradle插件」我的意思是當我向''build.gradle'文件中添加'apply plugin:「com.jfrog.artifactory」'時,無論插入什麼內容。 – IAmYourFaja 2014-12-05 14:30:30

+1

hm,儘量擺脫'maven'或'maven-publish'插件。你不應該同時使用它們。 – JBaruch 2014-12-05 14:53:28

相關問題