java - 使用子模块发布到 Maven Central

标签 java maven

我有一个包含多个模块的项目。我大部分都使用 pom 打包,当然还有一些 jar 模块。 现在,我需要在 Maven Central 上进行部署。我关注了this tutorial .

当我运行建议的 sh 脚本时

!/bin/bash
read -p "Really deploy to maven central repository  (yes/no)? "
if ( [ "$REPLY" == "yes" ] ) then
  ssh-add ~/.ssh/id_rsa
  ssh-add -l
  mvn release:clean release:prepare release:perform -B -e | tee maven-central-deploy.log
  ssh-add -D
else
  echo 'Exit without deploy'
fi

在步骤

mvn release:clean release:prepare release:perform -B -e | tee maven-central-deploy.log

该命令在执行步骤中惨败,并显示以下我不理解的消息

INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project blaster-core: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]
[INFO] [ERROR] 
[INFO] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[INFO] [ERROR] Re-run Maven using the -X switch to enable full debug logging.
[INFO] [ERROR] 
[INFO] [ERROR] For more information about the errors and possible solutions, please read the following articles:
[INFO] [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

我觉得一切都好。难道是因为我只在jar打包的模块中添加了以下内容?

<distributionManagement>
    <snapshotRepository>
        <id>ossrh</id>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </snapshotRepository>
</distributionManagement>

个人资料是:

    <profile>
        <id>release</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.sonatype.plugins</groupId>
                    <artifactId>nexus-staging-maven-plugin</artifactId>
                    <version>1.6.6</version>
                    <extensions>true</extensions>
                    <configuration>
                        <serverId>ossrh</serverId>
                        <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                        <autoReleaseAfterClose>true</autoReleaseAfterClose>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>2.4</version>
                    <executions>
                        <execution>
                            <id>attach-sources</id>
                            <goals>
                                <goal>jar-no-fork</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>2.10.3</version>
                    <executions>
                        <execution>
                            <id>attach-javadocs</id>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-gpg-plugin</artifactId>
                    <version>1.5</version>
                    <executions>
                        <execution>
                            <id>sign-artifacts</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>sign</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>versions-maven-plugin</artifactId>
                    <version>2.2</version>
                    <configuration>
                        <generateBackupPoms>false</generateBackupPoms>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

最佳答案

May it be that it is because I added the following only in the modules with jar packaging?

是的,如果您从项目结构的顶层运行发布,并且模块找不到其 <distributionManagement> 的定义,那么 Maven 将不知道如何发布该模块。推荐的方法是定义 <distributionManagement>在项目中所有其他模块继承的父 pom.xml 中。这样,设置就可以保存在一个位置。

...I don't need to release the modules with pom packaging but just those with jar packaging.

我假设您使用 pom 打包的原因是其中一些 jar 模块正在使用项目继承来从 pom 模块继承。如果是这样,那么您实际上需要发布使用 pom 打包的模块。这是因为当其他项目使用<dependency>时在您的 jar 模块上,Maven 也必须能够找到父 pom.xml,以便完全解析该项目的定义,以进行相关操作,例如查找所有传递依赖项。

关于java - 使用子模块发布到 Maven Central,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34499911/

相关文章:

java - Spring Boot SLF4J 日志记录性能

java - 在 React Native Android 应用程序中通过 crashlytics 的堆栈跟踪找到崩溃是真的吗?

java - 使用 SplitVerifier Java 7 到 Java 9

Maven maven-deploy-plugin 总是上传两次

Maven 清理忽略单个文件

maven - 即使我没有在任何地方配置它,Android Gradle Build 也会尝试访问 JCenter

java - 如何在 double 中将小数点设置为只有 2 位数字?

java - 如何检测 Spinner 是否在 Android 上单击打开

java - 在 Java 中将数组排序为第二个数组

java - 带有 Maven 和子项目的 Playframework 2.0