簡體   English   中英

使用子模塊發布到Maven Central

[英]Release to Maven Central with submodules

我有一個包含多個模塊的項目。 我對大多數包裝使用pom包裝,當然還有一些jar模塊。 現在,我需要在Maven Central上進行部署。 我遵循了本教程

當我運行建議的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

該命令在perform步驟時不幸失敗, perform帶有以下我不理解的消息

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>

可能是因為我僅在具有jar包裝的模塊中添加了以下內容?

是的,如果您從項目結構的頂層運行發行版,而某個模塊找不到其<distributionManagement>的定義,那么Maven將不知道如何發行該模塊。 推薦的方法是在項目中所有其他模塊都繼承的父pom.xml中定義<distributionManagement> 這樣,可以將設置保存在一個位置。

...我不需要發布帶有pom包裝的模塊,而只需發布帶有jar包裝的模塊。

我假設您使用pom打包的原因是其中一些jar模塊使用項目繼承從pom模塊繼承。 如果是這樣,那么實際上您確實需要釋放使用pom打包的模塊。 這是因為,當其他項目在jar模塊上使用<dependency>時,Maven也必須能夠找到父pom.xml,以便完全解決該項目的定義,例如查找所有可傳遞依賴項。

我怎么解決的。

我將distributionManagement部分替換為

<distributionManagement>
    <snapshotRepository>
        <id>ossrh</id>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </snapshotRepository>
    <repository>
        <id>ossrh</id>
        <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
    </repository>
</distributionManagement>

我將這部分內容和release資料放在所有模塊中。 我很確定我可以以某種方式繼承它,但是現在就足夠了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM