要配置插件描述符的生成,请将以下内容添加到项目的 POM 中:
<project> ... <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-plugin-plugin</artifactId> <version>3.6.4</version> <configuration> <goalPrefix>plugin</goalPrefix> <outputDirectory>target/dir</outputDirectory> </configuration> </plugin> </plugins> ... </build> ... </project>
该goalPrefix
参数将为描述符中指定的插件设置目标前缀。outputDirectory
另一方面,该参数指定生成的插件描述符的目标位置。
例如,如果我们参考Maven Archetype 插件生成的MyMojo
来源maven-my-plugin
,即:
mvn archetype:create \ -DgroupId=org.apache.maven.plugin.my \ -DartifactId=maven-my-plugin \ -DarchetypeArtifactId=maven-archetype-mojo
生成的插件描述符mvn package
应该是:
<plugin> <description></description> <groupId>org.apache.maven.plugin.my</groupId> <artifactId>maven-my-plugin</artifactId> <version>1.0-SNAPSHOT</version> <goalPrefix>my</goalPrefix> <isolatedRealm>false</isolatedRealm> <inheritedByDefault>true</inheritedByDefault> <mojos> <mojo> <goal>touch</goal> <description>Goal which touches a timestamp file.</description> <requiresDirectInvocation>false</requiresDirectInvocation> <requiresProject>true</requiresProject> <requiresReports>false</requiresReports> <aggregator>false</aggregator> <requiresOnline>false</requiresOnline> <inheritedByDefault>true</inheritedByDefault> <phase>process-sources</phase> <implementation>org.apache.maven.plugin.my.MyMojo</implementation> <language>java</language> <instantiationStrategy>per-lookup</instantiationStrategy> <executionStrategy>once-per-session</executionStrategy> <parameters> <parameter> <name>outputDirectory</name> <type>java.io.File</type> <required>true</required> <editable>true</editable> <description>Location of the file.</description> </parameter> </parameters> <configuration> <outputDirectory implementation="java.io.File">${project.build.directory}</outputDirectory> </configuration> </mojo> </mojos> <dependencies> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> <type>jar</type> <version>2.0</version> </dependency> </dependencies> </plugin>