gpt4 book ai didi

java - Nexus & Maven Corporate Pom - 它应该包含什么?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:40:58 25 4
gpt4 key购买 nike

我们目前正在评估为我们的 java 开发建立一个内部公司关系存储库。

很遗憾,还有一些问题没有得到解答,但也许您可以提供帮助。

公司内部所有项目的父 pom 似乎是最佳实践。不清楚的是除了 <organization> 之外,这个 pom 应该包含什么部分。

同时指定 <distributionManagement> 是否是最佳实践?在这个 pom 里面?如果是,它应该包含什么?如果我们想引用公司关系(<site><repository><snapshotRepository>),它应该是什么样子?

如何处理这样一个事实(根据 sonatype)每个项目都有自己的存储库而不需要在每个 pom 中指定 nexus 根路径是最佳实践?

我们还应该指定 <repositories> 吗?和 <pluginRepositories>那里的部分(引用我们的内部联系)?

此外,我们希望基本上每个项目都可以部署自己的站点,我们能否在父 pom 中也指定这一点?如果是,站点插件配置应该是什么样的?

最好是有人可以提供一个完整的、示例性的公司 pom,可以与内部 nexus 存储库一起使用。

或者将这些东西放在 settings.xml 中会更好吗?不将项目绑定(bind)到某个存储库?但据我所知<distributionManagement>不能在settings.xml里面指定?如果某天 nexus url 发生变化,这将是一项繁琐的更新工作吗?

尽管我尝试阅读很多相关内容,但我对这整件事真的很困惑。

提前致谢!


更新/解决方案

感谢Michael-O下面的答案我有我需要的信息。

  1. <repositories><pluginRepositories>标签属于 settings.xml .这是指定nexus仓库的地方用于“下载”(可选地包括使用 <servers>
  2. 的凭据
  3. <distributionManagement>属于企业基地pom,为发布和快照引用一个基本的 Nexus 存储库。这是为“上传”(部署)指定 nexus 存储库的地方。
  4. 如果需要子存储库(用于逻辑分组项目),它们在项目内指定 pom.xml因此覆盖公司 pom 中的那些。为了简化这一点并仅将基本的联系 url 保留在公司 pom 中(注意 url 更改),在 <distributionManagement> 中指定存储库可能是有用的/可能的。通过以下方式:

    <repository>
    <id>company-repository</id>
    <name>Internal Releases</name>
    <url>http://my.nexus.repo/releases/${subRepositoryId}-releases</url>
    </repository>
  5. 可以在 this post 中找到示例性的公司 pom

  6. 要防止 pom 文件或设置中的配置更改,可以使用别名作为 nexus url。尽管这意味着行政方面需要付出额外的努力。
  7. 如果项目需要站点,则不能使用公司 pom 中的一般定义,必须为每个项目 pom 单独声明它。为了简化这个过程,站点关系 url 可以存储在公司 pom 的一个属性中,然后可以在项目 poms 的站点分发管理中引用它。

企业 pom 可能包含类似这样的内容:

  <project>
....
<properties>
<repository.group>common</repository.group>
<repository.url.base>http://my.nexus:port/nexus/content</repository.url.base>
<repository.url.repositories>${repository.url.base}/repositories</repository.url.repositories>
<repository.url.sites>${repository.url.base}/sites</repository.url.sites>
</properties>

<distributionManagement>
<repository>
<id>company-repository</id>
<name>Internal Releases</name>
<url>${repository.url.repositories}/${repository.group}-releases</url>
</repository>
<snapshotRepository>
<id>company-repository</id>
<name>Internal Snapshots</name>
<url>${repository.url.repositories}/${repository.group}-snapshots</url>
</snapshotRepository>
</distributionManagement>
....
</project>

项目pom与此类似:

  <project>
...
<properties>
<repository.group>project-group</repository.group>
</properties>

<distributionManagement>
<site>
<id>company-repository</id>
<name>Internal Releases</name>
<url>dav:${repository.url.sites}/project-site</url>
</site>
</distributionManagement>
...
</project>

警告:有人可能想知道为什么不直接将站点部分包含到企业 pom 中。这是不可能的,因为您不能在不造成困惑的情况下将多个站点部署到同一个站点存储库。使用上述方式不需要为每个项目创建一个存储库,而是能够将它们逻辑地分组到更大的组中,或者将它们留在 common-releases/snapshots 组/存储库中。

最佳答案

您可以查看 Apache Parent POM 或 Maven Parent POM。一个最小的企业 POM 应该是这样的:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>example-parent</artifactId>
<version>1-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Exmaple Parent POM</name>
<organization>
<name>Example Inc.</name>
</organization>

<!-- This marked as deprecated for Maven 3.x. This is checked by maven-enforcer-plugin -->
<!-- http://jira.codehaus.org/browse/MNG-5297 -->
<prerequisites>
<maven>${maven.version}</maven>
</prerequisites>

<scm>
<connection>scm:svn:https://example.com/repos/svn/ExmapleJava/example-parent/trunk/</connection>
<developerConnection>scm:svn:https://example.com/repos/svn/ExmapleJava/example-parent/trunk/</developerConnection>
<url>https://example.com/repos/websvn/browse/ExmapleJava/example-parent/trunk/</url>
</scm>

<distributionManagement>
<repository>
<id>nexus-example</id>
<name>Nexus Exmaple Release Repository</name>
<url>https://example.com/nexus/content/repositories/example-releases</url>
</repository>
<snapshotRepository>
<id>nexus-example</id>
<name>Nexus Exmaple Snapshot Repository</name>
<url>https://example.com/nexus/content/repositories/example-snapshots</url>
</snapshotRepository>
</distributionManagement>

<properties>
<maven.version>3.2</maven.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<surefire.version>2.19</surefire.version>
<javadoc.version>2.10.3</javadoc.version>
</properties>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<configuration>
<excludeResources>true</excludeResources>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<mavenExecutorId>forked-path</mavenExecutorId>
<autoVersionSubmodules>true</autoVersionSubmodules>
<useReleaseProfile>false</useReleaseProfile>
<tagNameFormat>@{project.version}</tagNameFormat>
</configuration>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<plugin>
<artifactId>maven-help-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${javadoc.version}</version>
<configuration>
<quiet>true</quiet>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.6.1</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.4</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<buildNumberPropertyName>buildRevision</buildNumberPropertyName>
<timestampPropertyName>buildTimestamp</timestampPropertyName>
<scmBranchPropertyName>buildScmBranch</scmBranchPropertyName>
<revisionOnScmFailure>non-SCM</revisionOnScmFailure>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<generateBackupPoms>false</generateBackupPoms>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.10</version>
<configuration>
<includeConfigurationDirectoryInClasspath>false</includeConfigurationDirectoryInClasspath>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
</plugin>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>${maven.version}</version>
<message>This project requires at least Maven ${maven.version}</message>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>example-release</id>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

插件当然会因您的公司而异,但这可以帮助您入门。这实际上是我们的家长刚刚删除了我们的本地信息。

没有站点部署的信息,因为我们不使用它。如果你使用它,请设置它。

没有的时候你的 POM 应该包含 <repositories><pluginRepositories>因为这是不好的做法。理想情况下,您与 Nexus 镜像(在 settings.xml 中)中的 repo 组一起工作,您的所有请求。

继承并快乐。

如何处理网站:通常,每个项目都有自己的站点,应该在 dist mngt 部分中覆盖。这与人工制品不同。您将托管在 Nexus 上还是托管在像 Apache 这样的网络服务器上取决于您。底线是每个项目站点都需要其不同的 URL。

关于java - Nexus & Maven Corporate Pom - 它应该包含什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33522364/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com