在发布时匿名化 pom.xml
我有使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道您的问题的完美解决方案,但有些事情可以做。这些都是技巧,但它们可能会有所帮助。
首先,从 pom 中外部化私有信息(如 scm、开发人员名称等)。对于 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:
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.
据我所知,发布插件没有对此的内置支持。我想到了两种可能性:
选项 1:
我认为选项 1 很恶心。
选项 2:
我认为选项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:
<archive><addMavenDescriptor>false</addMavenDescriptor></archive>
I think Option 1 is yucky.
Option 2:
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.
您将为此创建自己的原型并将其发布给公众。然后,您的用户可以检索原型并根据您的原型设置他们自己的项目。
原型是一个非常简单的插件,其中包含希望创建的项目原型。
要基于原型创建新项目,需要调用 mvn archetype:generate 目标,如下所示:
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: