简体   繁体   中英

Creating maven custom plugin

I have created a custom plugin in Maven. However, the jar file that is created has the name CustomPlugin-1.0.jar.lastUpdated 'lastUpdated' is the extension, and it's not possible to open the file due to it being corrupt.

The steps I followed to create it are as follows:

  • First I created a maven plugin using maven (created a maven project with packaging=maven-plugin ).
  • Then I put a class in there that extends AbstractMojo and contains the custom plugin code.
  • Then I built it with maven. Maven created the corrupt jar as mentioned above.

How do I create a valid jar file for a custom plugin?

Use maven-shade plugin to package your jar. It will automatically package and create a jar(fat-jar) with all the dependencies, resources and correct jar name and extension.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <version>3.0.0</version>
  <configuration>
    <!-- put your configurations here -->
  </configuration>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>shade</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Add this to your custom maven plugin pom and the build using mvn clean install .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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