jgitver / jgitver-maven-plugin

maven core extension to automatically define versions using jgitver & git tags
https://jgitver.github.io/
Other
159 stars 42 forks source link

jgitver extension not run by m2e incremental builds #147

Open Brixomatic opened 3 years ago

Brixomatic commented 3 years ago

Issue

version: 1.7.1

usage context: Eclipse m2e

I have a file generated, using jgitver variables

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-resources-plugin</artifactId>
  <version>3.2.0</version>
  <executions>
    <execution>
      <id>generate-version-template</id>
      <phase>generate-sources</phase>
      <goals>
          <goal>copy-resources</goal>
      </goals>
      <configuration>
        <outputDirectory>${project.basedir}/info/</outputDirectory>
        <resources>
          <resource>
        <directory>${project.basedir/templates}</directory>
        <includes>
            <include>latest_release.xml</include> <!-- COPY THIS FILE -->
        </includes>
        <filtering>true</filtering> <!-- FILTER FILE (SUBSTITUTE VARIABLES) -->
          </resource>
        </resources>
        <encoding>UTF-8</encoding>
      </configuration>
    </execution>
  </executions>
</plugin>

where templates/latest_release.xml will look like this:

<dependency>
  <groupId>some.group.id</groupId>
  <artifactId>some.artifact.id</artifactId>
  <version>${jgitver.base_tag}</version> <!-- TEMPLATE HAS A VARIABLE -->
</dependency>

When running "run as maven install" in Eclipse, the file is generated and the version is substituted, as expected:

info/latest_release.xml will look like this:

<dependency>
  <groupId>some.group.id</groupId>
  <artifactId>some.artifact.id</artifactId>
  <version>1.2.0</version>  <!-- COPIED FILE HAS THE VARIABLE REPLACED -->
</dependency>

When pressing "save" on any project, Eclipse m2e will to an incremental build and the file will be recreated as: info/latest_release.xml:

<dependency>
  <groupId>some.group.id</groupId>
  <artifactId>some.artifact.id</artifactId>
  <version>${jgitver.base_tag}</version> <!-- NO VARIABLE SET DURING INCREMENTAL BUILD (= revert substitution) -->
</dependency>

Clearly, m2e seems to not run jgitver on an incremental build, so that the variables are not substituted.

As an effect, the files only look as they should for a few seconds between the "mvn install" and the automatic m2e incremental build.

I also cannot seem to force Eclipse e2e to invoke jgitver, using a lifecycle-mapping, like so, as the jgitver-extension does not seem to have a goal I could specify to run it:

<pluginManagement>
  <plugins>
    <plugin>
      <groupId>org.eclipse.m2e</groupId>
      <artifactId>lifecycle-mapping</artifactId>
      <version>1.0.0</version>
      <configuration>
        <lifecycleMappingMetadata>
          <pluginExecutions>
            <pluginExecution>
              <pluginExecutionFilter>
        <groupId>fr.brouillard.oss</groupId>
        <artifactId>jgitver-maven-plugin</artifactId>
                <versionRange>[1.0.0,)</versionRange>
                <goals>
                  <goal>some-goal</goal> <!-- UNKNOWN GOAL -->
                </goals>
              </pluginExecutionFilter>
              <action>
                <execute>
                  <runOnIncremental>true</runOnIncremental>
                  <runOnConfiguration>true</runOnConfiguration>
                </execute>
              </action>
            </pluginExecution>
          </pluginExecutions>
        </lifecycleMappingMetadata>
      </configuration>
    </plugin>
  </plugins>
</pluginManagement>

The only solution that I came up with is to try to stop the resource filtering plugin using a lifecycle-mapping, but this would stop all filtering activities in a build.

McFoggy commented 3 years ago

As it looks to be a m2e issue what do you expect from jgitver-maven-plugin ? the introduction of a specific goal that would fill the jgitver. properties ?

Brixomatic commented 3 years ago

As it looks to be a m2e issue what do you expect from jgitver-maven-plugin?

I would have expected that it sets the parameters always, but maybe it's the extension nature that makes m2e not invoke jgitver. If I look at the m2e lifecycle mapping in Eclipse, I see that for example the compiler is an extension that is bound to a "configurator":
image
So it seems there is a way to bind extension goals to some lifecycle phase. Since I don't exactly know how the internals of the extension mechanism works, I thought I'd leave this here.

the introduction of a specific goal that would fill the jgitver. properties ?

Yes, I think it could be helpful to have a jgitver goal that does this, preferably bound to the validate phase. At least it seems as I could explicitly request this to be executed in the pom.xml (see xml pasted in the issue description).

McFoggy commented 3 years ago

no https://maven.apache.org/plugins/maven-compiler-plugin is not an extension it is a plugin.

IDEs in general bypass the extensions because extensions have the power to dynamically change the initial POM (in memory Project Object Model). For example polyglot-maven build the POM from yaml/java/scala/json, jgitver modifies the version and introduces some plugins executions in the POM. For IDEs it is easier just to read the pom.xml file bypassing what the extensions are doing.

Exposing a plugin/goal filling the properties is I think the way to go here.