I have create a custom maven plugin to upload the generated artifacts and
dependent artifacts to a development server.

If I bind the goal of this plugin to a specific lifecycle phase, it runs
well:

----/----
<build>
  <plugins>
    <plugin>
      <groupId>mygroupid</groupId>
      <artifactId>myplugin</artifactId>
      <version>1.0</version>
      <configuration>
         ...
      </configuration>
      <executions>
        <execution>
          <goals>
            <goal>upload</goal>
          </goals>
        </execution>
      </executions>
     <plugin>
  </plugins>
</build>
----/----

However, I do not want to bind this goal to a specific phase, but instead
want to call it on demand. The problem is that the plugin then doesn't
find the jar file of the project artifact (the files for the dependencies
are found). Here is the relevant code snippet of the plugin:

----/----
public class MyMojo extends AbstractMojo {
  @Parameter(property = "project", required = true, readonly = true)
  private MavenProject project;

  @Override
  public void execute() throws MojoExecutionException {
    final Set<Artifact> artifacts = project.getArtifacts();

    artifacts.stream().forEach((artifact) -> {
      getLog().info("Dependency: "+artifact.getFile());   // WORKS! Every
jar file is found
   });
   getLog().info("Project artifact: "+project.getArtifact().getFile());
// DOES NOT WORK! Returns null
 }
}
----/----

Actually what I want is, that the execution of the goal of this plugins
depends on the execution of the package phase (to have the jar generated).
But I want that the plugin only gets executed if the user explicitly
invokes the goal.

What am I doing wrong?
How can I achieve my goal?

Best regards
Marco


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to