【问题标题】:Gradle maven-publish for Spring-Boot project throws error: Cannot find parent: org.springframework.boot:spring-boot-starter-parent for projectSpring-Boot 项目的 Gradle maven-publish 抛出错误:找不到父项:项目的 org.springframework.boot:spring-boot-starter-parent
【发布时间】:2014-12-31 19:42:37
【问题描述】:

我是 Gradle 新手,因此我们将非常感谢任何有关此错误的帮助。

我正在使用 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

我错过了什么?

提前感谢您的帮助。

【问题讨论】:

    标签: gradle spring-boot


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      与@aardee 一样,我坐在公司防火墙后面,但我的本地 maven 代理设置 (settings.xml) 似乎没有改变任何东西。幸运的是,我们有自己的 maven 存储库,可以代理出去,所以我只是替换了生成的 pom 中的存储库,并确保我们公司的 maven 存储库知道相关的 spring 存储库。

      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}
      

      http://my.mavenRepo.com/releases 替换为您自己的 maven 存储库。

      【讨论】:

        猜你喜欢
        • 2023-02-07
        • 2021-03-05
        • 2021-08-22
        • 2021-10-22
        • 2018-12-01
        • 1970-01-01
        • 2021-03-29
        • 2017-07-06
        • 1970-01-01
        相关资源
        最近更新 更多