Maven 发布“maven”不能包含多个组件/发布仅包含没有版本的依赖项和/或约束

问题描述 投票:0回答:0

这是我的项目结构:

- snow
  - snow-lib
    - snow-base-util
    - snow-web-common
  - snow-web
    - snow-user

这是代码,很简单。 https://github.com/site-weic/snow

案例一

当我配置snow-web-common发布到Maven Local时,它发布成功(分支case1)。

  • snow-lib/snow-base-util/build.gradle 是空的
  • snow-lib/snow-web-common/build.gradle
dependencies {
    api 'org.springframework.boot:spring-boot-starter-web'
    api project(':snow-lib:snow-base-util')
}
java {
    withJavadocJar()
    withSourcesJar()
}
publishing {
    publications {
        maven(MavenPublication) {
            groupId = project.group
            artifactId = project.name
            version = project.version

            from components.java
        }
    }
}

案例二

但是配置snow-base-util会报错(branch case2)

A problem occurred evaluating project ':snow-lib:snow-web-common'.
> Maven publication 'maven' cannot include multiple components

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
  • snow-lib/snow-base-util/build.gradle
java {
    withJavadocJar()
    withSourcesJar()
}
publishing {
    publications {
        maven(MavenPublication) {
            groupId = project.group
            artifactId = project.name
            version = project.version

            from components.java
        }
    }
}
  • snow-lib/snow-web-common/build.gradle
dependencies {
    api 'org.springframework.boot:spring-boot-starter-web'
    api project(':snow-lib:snow-base-util')
}
java {
    withJavadocJar()
    withSourcesJar()
}
publishing {
    publications {
        maven(MavenPublication) {
            groupId = project.group
            artifactId = project.name
            version = project.version

            from components.java
        }
    }
}

案例三

配置同时发布两个项目会报错(分支case3)

Execution failed for task ':generateMetadataFileForMavenPublication'.
> Invalid publication 'maven':
    - Publication only contains dependencies and/or constraints without a version. You need to add minimal version information, publish resolved versions (https://docs.gradle.org/7.4/userguide/publishing_maven.html#publishing_maven:resolved_dependencies) or reference a platform (https://docs.gradle.org/7.4/userguide/platforms.html)

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
  • snow-lib/snow-base-util/build.gradle
java {
    withJavadocJar()
    withSourcesJar()
}
publishing {
    publications {
        maven(MavenPublication) {
            groupId = project.group
            artifactId = project.name
            version = project.version

            from components.java
        }
    }
}
  • snow-lib/snow-web-common/build.gradle
dependencies {
    api 'org.springframework.boot:spring-boot-starter-web'
    api project(':snow-lib:snow-base-util')
}

如何修复gradle配置? 还有,gradle 打包多模块项目的最佳实践是什么?能否请您提供一些 Github 或 Books 上的参考项目? 谢谢!!!🙋u200d♂️

spring-boot gradle maven-plugin
© www.soinside.com 2019 - 2024. All rights reserved.