Maven 3 - Distribute custom plugin in .jar?

Fill in Maven newb here, so forgive any abused terminology, etc.

I created my own plugin in Maven 3 (one that defines goals for git rebase). I can:

mvn install 

No problems. Then I can call the target from the command line:

 mvn edu.clemson.cs.rsrg:git-plugin:rebase 

All is golden. I have this beautiful git -plugin-XXX.jar file located in my target directory.

I would like to make my custom goals available for another project, so when other members of the development team pull this source of the project, they get my plugin for free (or at least after mvn build ).

I understand that the purist solution is to set up the maven repository for the group and load my plugin there, but that seems redundant for one hacked plugin.

Thoughts?


I played with this through three different plugins:

  • addjars-maven-plugin:add-jars

      <plugin>
        <groupId> com.googlecode.addjars-maven-plugin </groupId>
        <artifactId> addjars-maven-plugin </artifactId>
        <version> 1.0.4 </version>
        <executions>
           <execution>
              <goals>
                 <goal> add-jars </goal>
              </goals>
              <configuration>
                 <resources>
                    <resource>
                       <directory> $ {basedir} / plugins </directory>
                    </resource>
                 </resources>
              </configuration>
           </execution>
        </executions>
     </plugin>
    

Gives me this error during mvn build :

[ERROR] Error resolving version for plugin 'edu.clemson.cs.rsrg:git-plugin' from the repositories [local (/home/hamptos/.m2/repository), central (http://repo.maven.apache.org/maven2)]: Plugin not found in any plugin repository

This also crashes my later formatting plugin. (It’s clear that he read the jar and determined the group name / plugin name, but then he goes and looks for it in my local repo? Of course not, I'm trying to install it.)

  • build-helper:attach-artifacts

      <plugin>
        <groupId> org.codehaus.mojo </groupId>
        <artifactId> build-helper-maven-plugin </artifactId>
        <version> 1.7 </version>
        <executions>
           <execution>
              <id> attach-artifacts </id>
              <phase> install </phase>
              <goals>
                 <goal> attach-artifact </goal>
              </goals>
              <configuration>
                 <artifacts>
                    <artifact>
                       <file> $ {basedir} /plugins/git-plugin-0.1.0a.jar </file>
                       <type> jar </type>
                    </artifact>
                 </artifacts>
              </configuration>
           </execution>
        </executions>
     </plugin>
    

Gives me this error during mvn build :

[ERROR] Failed to execute goal org.codehaus.mojo:build-helper-maven-plugin:1.7:attach-artifact (attach-artifacts) on project RESOLVE: Execution attach-artifacts of goal org.codehaus.mojo:build-helper-maven-plugin:1.7:attach-artifact failed: For artifact {edu.clemson.cs.rsrg:RESOLVE:12.09.01a:jar}: An attached artifact must have a different ID than its corresponding main artifact.

(RESOLVE: 12.09.01a - the main project). Obviously, something went wrong here, because there are definitely different artifacts in the plugin and the main project. An attempt to attach the project on top of itself, maybe?)

  • maven-install-plugin:install-file

      <plugin>
        <groupId> org.apache.maven.plugins </groupId>
        <artifactId> maven-install-plugin </artifactId>
        <version> 2.3.1 </version>
        <executions>
           <execution>
              <id> install-git-plugin </id>
              <phase> initialize </phase>
              <goals>
                 <goal> install-file </goal>
              </goals>
              <configuration>
                 <file> $ {basedir} /plugins/git-plugin-0.1.0a.jar </file>
                 <packaging> jar </packaging>
                 <groupId> edu.clemson.cs.rsrg </groupId>
                 <artifactId> git-plugin </artifactId>
                 <version> 0.1.0a </version>
              </configuration>
           </execution>
        </executions>
     </plugin>
    

It seems to work fine until I try to call one of the targets like mvn edu.clemson.cs.rsrg:git-plugin:rebase , and at that moment it gives me this error:

[ERROR] Failed to execute goal edu.clemson.cs.rsrg:git-plugin:0.1.0a:rebase (default-cli) on project RESOLVE: Execution default-cli of goal edu.clemson.cs.rsrg:git-plugin:0.1.0a:rebase failed: Unable to load the mojo 'rebase' (or one of its required components) from the plugin 'edu.clemson.cs.rsrg:git-plugin:0.1.0a': com.google.inject.ProvisionException: Guice provision errors: [ERROR] [ERROR] 1) Error in ComponentFactory:ant-mojo [ERROR] at ClassRealm[plugin>edu.clemson.cs.rsrg:git-plugin:0.1.0a, parent: sun.misc.Launcher$AppClassLoader@e776f7 ] [ERROR] while locating org.apache.maven.plugin.Mojo annotated with @com.google.inject.name.Named(value=edu.clemson.cs.rsrg:git-plugin:0.1.0a:rebase)

+4
source share
1 answer

You might think this is hacked, but this is the maven way. It should be deployed in a maven repo.

If you save it in a group that you can explicitly demonstrate and open source, you can publish it in the center

0
source

Source: https://habr.com/ru/post/1433639/


All Articles