代码之家  ›  专栏  ›  技术社区  ›  mhaller

发布时匿名化pom.xml

  •  4
  • mhaller  · 技术社区  · 15 年前

    我有一些人工制品,它们是用Maven构建和发布的。

    有没有办法告诉Maven生成一个经过消毒的pom.xml,这样就可以向公众发布工件,而不会破坏技术相关信息,比如依赖关系?

    总结如下:

    我有:

    <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>
    
    3 回复  |  直到 15 年前
        1
  •  3
  •   cetnar    15 年前


    首先,从pom外部化私有信息(如scm、开发人员姓名等)。对于scm元数据,它将是:

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

    第二,将属性移动到 settings file 将它们放置在配置文件中。在设置文件中,您还可以“隐藏”公司的私有存储库。如果必须与其他同事共享profiles/settings.xml文件,请尝试使用全局设置文件 mvn -gs path_to_global_settings 或者在准备好这些设置的情况下准备common Maven安装。
    不幸的是,父pom部分必须保持不变。

        2
  •  1
  •   Zac Thompson    15 年前

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

    备选案文1:

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

    • 尝试将preparationGoals参数用于发布插件。如果可以将pom操作编写为maven操作,那么 这样做是可能的。

    如果这些都不起作用,您可能需要使用release:stage之类的工具,并手动进行消毒,但您仍然希望将POM从罐子内容物中排除。

        3
  •  0
  •   Tom    15 年前

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

    mvn archetype:generate

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