在发布时匿名化 pom.xml

发布于 2024-08-11 09:20:34 字数 1380 浏览 4 评论 0原文

我有使用 Maven 构建和发布的工件。 artefact的原始pom.xml包含通常的项目信息(artifactId、名称等)和依赖项。没关系。但 pom.xml 还包含私有信息,例如 SCM URL、开发人员的名称或父工件。

有没有什么方法可以告诉 Maven 生成经过清理的 pom.xml,以便可以将工件发布给公众,而不破坏依赖项等技术相关信息?

SCM URL、开发人员列表和父 pom(仅用于 DepMgmt 定义和其他元内容)的存在与该工件的用户无关,所以我假设我可以从发布的 pom.xml

存储库管理器(例如 Archiva)中的 pom.xml 以及打包在 artefact 的 jar 文件中的 pom.xml 都包含这些信息。我认为 Maven 只是复制整个内容。

总结一下:

我有:

<project>
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.example</groupId>
   <artifactId>my-artifact</artifactId>
    <scm>
        <connection>scm:svn:http://buildmachine/org.example/my-artifact/trunk</connection>
        <developerConnection>scm:svn:http://buildmachine/org.example/my-artifact/trunk</developerConnection>
        <url>http://buildmachine/org.example/my-artifact/trunk</url>
    </scm>
    <dependencies>
        <dependency>
            ...
        </dependency>
    </dependencies>

我想要:

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.example</groupId>
    <artifactId>my-artifact</artifactId>
    <dependencies>
        <dependency>
            ...
        </dependency>
    </dependencies>

I've got artefacts which are built and released using Maven.
The artefact's original pom.xml contains the usual project information (artifactId, name, etc.) and the dependencies. That's fine. But the pom.xml also includes private information such as the SCM URLs, the names of the developers or a parent-artefact.

Is there any way to tell Maven to generate a pom.xml which is sanitized, so the artefact can be released to public, without destroying the technical relevant information such as the dependencies?

Neither the SCM URLs, nor the list of developers nor the existence of a parent-pom (which is only used for DepMgmt definitions and other meta-stuff) is imho relevant for users of the artefact, so I assume i could be removed from a released pom.xml

The pom.xml both in an repository manager such as Archiva and packaged within the artefact's jar file contain those informations. I assume Maven is just copying the whole thing.

To summarize:

I have:

<project>
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.example</groupId>
   <artifactId>my-artifact</artifactId>
    <scm>
        <connection>scm:svn:http://buildmachine/org.example/my-artifact/trunk</connection>
        <developerConnection>scm:svn:http://buildmachine/org.example/my-artifact/trunk</developerConnection>
        <url>http://buildmachine/org.example/my-artifact/trunk</url>
    </scm>
    <dependencies>
        <dependency>
            ...
        </dependency>
    </dependencies>

I want:

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.example</groupId>
    <artifactId>my-artifact</artifactId>
    <dependencies>
        <dependency>
            ...
        </dependency>
    </dependencies>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

就是爱搞怪 2024-08-18 09:20:34

我不知道您的问题的完美解决方案,但有些事情可以做。这些都是技巧,但它们可能会有所帮助。
首先,从 pom 中外部化私有信息(如 scm、开发人员名称等)。对于 scm 元数据,它将是:

<scm>
   <connection>${my.scm.connection}</connection>
   <developerConnection>${my.scm.developerConnection}</developerConnection>   
   <url>${my.scm.url}</url>
</scm>

其次,将属性移动到设置文件,将它们放入配置文件中。在设置文件中,您还可以“隐藏”您公司的私人存储库。如果您必须与其他同事共享 profile/settings.xml 文件,请尝试使用运行 mvn -gs path_to_global_settings 的全局设置文件或准备好这些设置后准备常见的 Maven 安装。
遗憾的是,父 pom 部分必须保持不变。

I don't know perfect solution for your problem, but some things can be done. These are hacks, but they might help.
First, externalize private information from pom (like scm, developer names etc.). For scm metadata it will be:

<scm>
   <connection>${my.scm.connection}</connection>
   <developerConnection>${my.scm.developerConnection}</developerConnection>   
   <url>${my.scm.url}</url>
</scm>

Second, move properties to settings file placing them in a profile. In settings file you can also "hide" your company private repository. If you must share profiles/settings.xml file with other associates, try to use global setting file running mvn -gs path_to_global_settings or prepare common Maven installation with these settings prepared.
Parent pom section unfortunately must stay untouched.

晨曦÷微暖 2024-08-18 09:20:34

据我所知,发布插件没有对此的内置支持。我想到了两种可能性:

选项 1:

  • 不要在 jar 中包含 pom - 您可以使用 jar 目标。 false
  • 编写一个程序来删除发布的 POM 中不需要的元素。您必须在release:prepare和release:perform之间执行此操作,这可能只有在您的SCM支持创建后修改标签时才有效,或者在不同的标签/分支下进行修改,然后release:perform那里。

我认为选项 1 很恶心。

选项 2:

  • 尝试利用发布插件的 PreparationGoals 参数。如果您可以将 pom 操作编写为 Maven 操作,那么可能可以通过这种方式实现。

我认为选项2更难。

如果这些都不起作用,您可能必须使用诸如release:stage之类的东西并手动进行清理,但您仍然希望从jar内容中排除POM。

The release plugin doesn't have built-in support for this, to my knowledge. Two possibilities come to mind:

Option 1:

  • Don't include the pom in your jars - you can control this using the 'archive' parameter to the jar goal. <archive><addMavenDescriptor>false</addMavenDescriptor></archive>
  • Write a program to strip out the elements you don't want in your published POM. You'd have to do this between release:prepare and release:perform, which would probably only work if you have support in your SCM for modifying tags after creation, or do the modification under a different tag/branch and then release:perform from there.

I think Option 1 is yucky.

Option 2:

  • try to leverage the preparationGoals parameter to the release plugin. If you can write the pom manipulation as maven actions, it might be possible to do it this way.

I think Option 2 is harder.

If none of that works, you'll probably have to use something like release:stage and do the sanitizing by hand, but you'd still want to exclude the POMs from the jar contents.

冬天的雪花 2024-08-18 09:20:34

您将为此创建自己的原型并将其发布给公众。然后,您的用户可以检索原型并根据您的原型设置他们自己的项目。

原型是一个非常简单的插件,其中包含希望创建的项目原型。

要基于原型创建新项目,需要调用 mvn archetype:generate 目标,如下所示:

  mvn archetype:generate                              \
  -DarchetypeGroupId=<archetype-groupId>              \
  -DarchetypeArtifactId=<archetype-artifactId>        \ 
  -DarchetypeVersion=<archetype-version>              \
  -DgroupId=<my.groupid>                              \
  -DartifactId=<my-artifactId>

You would create your own archetype for this and release it to the public. Your users then could retrieve the archetype and setup their own project based upon your archetype.

An archetype is a very simple plugin, that contains the project prototype one wishes to create.

To create a new project based on an archetype, one need to call mvn archetype:generate goal, like the following:

  mvn archetype:generate                              \
  -DarchetypeGroupId=<archetype-groupId>              \
  -DarchetypeArtifactId=<archetype-artifactId>        \ 
  -DarchetypeVersion=<archetype-version>              \
  -DgroupId=<my.groupid>                              \
  -DartifactId=<my-artifactId>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文