Maven 阴影插件似乎不使用分类器名称



当我使用 maven 创建 jar 文件并将配置文件与分类器一起使用时,着色的 jar 文件的名称中没有分类器。

Maven版本:Apache Maven 3.2.5

这是配置文件之一:

<profile>
<id>external</id>
<properties>
<envClassifier>external</envClassifier>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<configuration>
<classifier>external</classifier>
</configuration>
<id>external-package</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

但是,目标 jar 文件没有像我预期的那样命名(您可以看到大阴影 jar @111MB没有"外部"的分类名称:

  • 363 KB 原始 myjar-0.1-快照.jar
  • 111 MB myjar-0.1 快照.jar
  • 362 KB myjar-0.1-快照外部.jar

这是我的着色配置:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin.version}</version>
<configuration>
<createDependencyReducedPom>true
</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
---removed
</configuration>
</execution>
</executions>
</plugin>

我可以使用 shadedArtifactId 来强制输出文件的名称,但似乎不需要这样做。

有什么想法吗?

谢谢

根据我的经验,阴影插件采用主要工件并将其替换为着色工件。

如果您希望着色工件具有分类器,则应将这些配置添加到着色插件中:

<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>external</shadedClassifierName>

我不清楚为什么您需要配置文件或带有分类器的其他 jar 插件配置。 我认为您可以使用阴影插件来生成您想要的分类罐子。 阐明是否有某些要求强制您使用配置文件。

所以我能够通过使用 finalName 属性来工作。 如果其他人使用这种技术或是否有其他解决方案,会很好奇。

<profile>
<id>external</id>
<properties>
<envClassifier>internal</envClassifier>
</properties>
<build>
<finalName>${project.artifactId}-${project.version}-external</finalName>
</build>
</profile>
</profiles>

最新更新