简体   繁体   English

使用分类器进行构建和工件时,Maven是否可以安装POM?

[英]Can Maven install POM when building and artifact with classifier?

I have a Maven project, which uses JAR packaging. 我有一个使用JAR打包的Maven项目。 When I run the install phase, it will install both Project-1.0.jar and Project-1.0.pom files in my local repository. 当我运行安装阶段时,它将在我的本地存储库中同时安装Project-1.0.jar和Project-1.0.pom文件。

Now I would like the JAR to be built with a classifier. 现在,我希望使用分类器构建JAR。 This is easy enough: I just add the line to my jar plugin configuration: 这很容易:我只需将行添加到我的jar插件配置中:

  <plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
      <classifier>whatever</classifier>   
      [...]
    </configuration>
  </plugin>

Now, this works in that it installs Project-1.0-whatever.jar in my repo, but no longer installs a POM. 现在,它的工作方式是在我的仓库中安装了Project-1.0-whatever.jar,但不再安装POM。

In case it matters, I want to use this feature in conjunction with profiles, ie I want to build JARs with different classifiers with different profiles. 万一重要,我想将此功能与配置文件结合使用,即,我想用具有不同配置文件的不同分类器来构建JAR。

The reason I want the POM is because I have other projects depending on this one. 我想要POM的原因是因为我还有其他项目依赖于此项目。 When I build one of these, it will try to find a POM for this dependency. 当我构建其中的一个时,它将尝试为此依赖项找到一个POM。 If it can't, it will happily use the JAR, but that is not an acceptable solution for me for a couple of reasons: 如果不能,它将愉快地使用JAR,但是由于以下几个原因,这对我来说不是可接受的解决方案:

It's bad enough that it will try to contact external repos and look for it, but even worse, we use a share repo, so it will download the POM from the shared repo, which may not be what I want - for example if I just made changes to the POM and am trying to test them. 它会尝试联系外部存储库并寻找它已经很糟糕了,但是更糟糕的是,我们使用共享存储库,因此它将从共享存储库下载POM,这可能不是我想要的-例如,如果我只是对POM进行了更改,并正在尝试对其进行测试。

Is there a solution, or can anyone suggest a reasonable workaround? 有解决方案,还是有人可以提出合理的解决方法?

EDIT: I just discovered that the issue affects Maven 2.2.1, but not Maven 3.0.5. 编辑:我刚刚发现该问题影响Maven 2.2.1,但不影响Maven 3.0.5。 This may therefore be a bug or a difference in features between versions. 因此,这可能是错误或版本之间的功能差异。 I would still be interested in solutions/workarounds for Maven 2, as migrating the project to Maven 3 is a complicated affair and not likely to happen. 我仍然会对Maven 2的解决方案/变通办法感兴趣,因为将项目迁移到Maven 3是一件复杂的事情,不太可能发生。

The reason turned out to be nothing to do with Maven version as such, and everything to do with the version of maven-install-plugin. 事实证明,原因与Maven这样的版本无关,与Maven-install-plugin的版本无关。 It turns out versions prior to 2.3 have this bug. 事实证明,2.3之前的版本存在此错误。

Old installations of Maven are somewhat likely to suffer this issue, as Maven 2 will use any version of a plugin that it has unless a version has been explicitly specified in the POM, but maven-install-plugin is included by default and it's quite possible for a POM not to explicitly specify it at all (as it was in my case). Maven的旧​​安装可能会遇到此问题,因为Maven 2将使用它具有的任何版本的插件,除非在POM中明确指定了版本,但默认情况下已包含maven-install-plugin,并且很有可能一个POM根本不明确指定它(就像我的情况一样)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM