2014-11-04 89 views
1

我是Gradle的新手,所以对此错误的任何帮助将不胜感激。Spring-Boot项目的Gradle Maven发布抛出错误:无法找到父项:org.springframework.boot:项目的spring-boot-starter-parent

我正在使用Spring-boot构建基于REST的服务。我想将JAR文件发布到本地Maven存储库,以便我的Web应用程序可以使用它。在尝试了很多事情之后,我终于找到了maven-publish插件。这是我的build.gradle文件

//Needed for spring-boot 
buildscript { 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.8.RELEASE") 
    } 
} 

apply plugin: 'eclipse' 

// Apply the groovy plugin to add support for Groovy 
apply plugin: 'groovy' 

//apply Spring-boot plugin 
apply plugin: 'spring-boot' 

apply plugin: 'maven-publish' 

// In this section you declare where to find the dependencies of your project 
repositories { 
    mavenLocal() 

    // Use 'jcenter' for resolving your dependencies. 
    // You can declare any Maven/Ivy/file repository here. 
    jcenter() 
    mavenCentral() 
} 

group = "com.proto" 

publishing { 
    publications { 
     maven(MavenPublication) { 
      groupId "${project.group}" 
      artifactId "${project.name}" 
      version "${project.jar.version}" 
      artifact sourceJar { classifier "sources" } 
      from components.java 

      pom.withXml { 
       asNode().appendNode('parent') 
         .appendNode('groupId', 'org.springframework.boot').parent() 
         .appendNode('artifactId', 'spring-boot-starter-parent').parent() 
         .appendNode('version', '1.1.8.RELEASE') 

       asNode().appendNode('repositories').appendNode('repository') 
         .appendNode('id', 'spring-releases').parent() 
         .appendNode('url', 'http://repo.spring.io/libs-release') 
      } 
     } 
    } 
} 

task sourceJar(type: Jar) { 
    from sourceSets.main.allJava 
} 

jar { 
    baseName = 'my-api' 
    version = '0.0.1' 
} 

task('execJar', type:Jar, dependsOn: 'jar') { 
    baseName = 'my-api' 
    version = '0.0.1' 
    classifier = 'exec' 
    from sourceSets.main.output 
} 

bootRepackage { 
    withJarTask = tasks['execJar'] 
} 

// In this section you declare the dependencies for your production and test code 
dependencies { 
    // We use the latest groovy 2.x version for building this library 
    compile 'org.codehaus.groovy:groovy-all:2.3.6' 

    compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1' 

    // tag::jetty[] 
    compile("org.springframework.boot:spring-boot-starter-web") 
// { 
// exclude module: "spring-boot-starter-tomcat" 
// } 
// compile("org.springframework.boot:spring-boot-starter-jetty") 
// end::jetty[] 

    // tag::actuator[] 
    compile("org.springframework.boot:spring-boot-starter-actuator") 

    // We use the awesome Spock testing and specification framework 
    testCompile 'org.spockframework:spock-core:0.7-groovy-2.0' 
    testCompile 'junit:junit:4.11' 
    testCompile('org.springframework.boot:spring-boot-starter-test') 
    testCompile('cglib:cglib:3.1') 
} 

// tag::wrapper[] 
task wrapper(type: Wrapper) { 
    gradleVersion = '2.1' 
} 

我的问题是,当我运行:

gradle publishToMavenLocal 

我得到以下错误:

FAILURE: Build failed with an exception. 

* What went wrong: 
Execution failed for task ':publishMavenPublicationToMavenLocal'. 
> Failed to publish publication 'maven' to repository 'MavenLocal' 
    > Unable to initialize POM pom-default.xml: Cannot find parent: org.springframework.boot:spring-boot-starter-parent for project: com.proto:proto-api:jar:0.0.1 for project com.proto:proto-api:jar:0.0.1 

我gradle这个环境的详细信息:

------------------------------------------------------------ 
Gradle 2.1 
------------------------------------------------------------ 

Build time: 2014-09-08 10:40:39 UTC 
Build number: none 
Revision:  e6cf70745ac11fa943e19294d19a2c527a669a53 

Groovy:  2.3.6 
Ant:   Apache Ant(TM) version 1.9.3 compiled on December 23 2013 
JVM:   1.7.0_72 (Oracle Corporation 24.72-b04) 
OS:   Linux 3.13.0-39-generic amd64 

我错过了什么?

非常感谢您的帮助。

回答

1

好吧,我已经解决了这个问题。 我在公司的防火墙后面,并且在〜/ .gradle/gradle.properties文件中为gradle正确配置了代理。但是,我错过了在〜/ .m2/settings.xml文件中为maven设置代理。

我配置了我们的内部联系存储库来处理这个问题,但是设置代理块也应该可以工作。 Click here for maven settings.xml documentation

1

与@aardee相同,我坐在公司防火墙后面,但似乎maven local的代理设置(settings.xml)没有改变任何东西。幸运的是,我们有我们自己的Maven仓库,可以进行代理,所以我只是替换了生成的仓库中的仓库,并确保我们公司的Maven仓库知道相关的春季仓库。

pom.withXml { 
      asNode().appendNode('parent') 
        .appendNode('groupId', 'org.springframework.boot').parent() 
        .appendNode('artifactId', 'spring-boot-starter-parent').parent() 
        .appendNode('version', '1.1.8.RELEASE') 

      asNode().appendNode('repositories').appendNode('repository') 
        .appendNode('id', 'spring-releases').parent() 
        .appendNode('url', 'http://my.mavenRepo.com/releases} 

用你自己的maven仓库替换http://my.mavenRepo.com/releases