我需要使用 Maven 创建 jar 文件,但它们需要以“foobar”扩展名安装到存储库中,如果它们可以有自己的打包类型,这样我们就可以通过打包来识别这些工件,那就太好了。
我可以设置新的包装类型来执行此操作吗?
要按照您的描述进行操作,请创建一个带有打包的 Maven 项目jar(就像声明的那样here,因为不会有 mojo 定义)。在 src/main/resources/META-INF/plexus 子文件夹中创建一个包含以下内容的 Components.xml (假设您希望打包类型为“my-custom-type”,如果您希望将其更改为“foobar”希望)。
<component-set>
<components>
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>my-custom-type</role-hint>
<implementation>
org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping
</implementation>
<configuration>
<phases>
<!--use the basic jar lifecycle bindings, add additional
executions in here if you want anything extra to be run-->
<process-resources>
org.apache.maven.plugins:maven-resources-plugin:resources
</process-resources>
<package>
org.apache.maven.plugins:maven-jar-plugin:jar
</package>
<install>
org.apache.maven.plugins:maven-install-plugin:install
</install>
<deploy>
org.apache.maven.plugins:maven-deploy-plugin:deploy
</deploy>
</phases>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>my-custom-type</role-hint>
<implementation>
org.apache.maven.artifact.handler.DefaultArtifactHandler
</implementation>
<configuration>
<!--the extension used by Maven in the repository-->
<extension>foobar</extension>
<!--the type used when specifying dependencies etc.-->
<type>my-custom-type</type>
<!--the packaging used when declaring an implementation of
the packaging-->
<packaging>my-custom-type</packaging>
</configuration>
</component>
</components>
</component-set>
然后在要具有自定义包装的 pom 中,在包装元素中声明所需的类型,并确保您已指定插件,以便可以贡献自定义包装。声明 true 告诉 Maven 该插件向 Maven 提供打包和/或类型处理程序。
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>name.seller.rich</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>my-custom-type</packaging>
<build>
<plugins>
<plugin>
<groupId>name.seller.rich.maven.plugins</groupId>
<artifactId>maven-foobar-plugin</artifactId>
<version>0.0.1</version>
<!--declare that this plugin contributes the component extensions-->
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
当项目打包时,它将是一个带有 .jar 扩展名的 jar,但是当安装/部署时,Maven 会将文件传递到具有“.foobar”扩展名的存储库,如在 elements.xml 中指定的那样
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)