0

I use maven-jgit-buildnumber-plugin(github) In one case I define it in profile:

<profile>
    <id>make-buildnumber</id>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
    <build>
        <plugins>
            <plugin>
                <groupId>ru.concerteza.buildnumber</groupId>
                <artifactId>maven-jgit-buildnumber-plugin</artifactId>
                <executions>
                    <execution>
                        <id>make-buildnumber</id>
                        <goals>
                            <goal>extract-buildnumber</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

In other case I point it in build section of the pom.xml.

In pluginManagement section I try to use variables from plugin:

<plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <archive>
            <manifestSections>
                <manifestSection>
                    <name>SCM</name>
                    <manifestEntries>
                        <Branch>${git.branch}</Branch>
                    </manifestEntries>
                </manifestSection>
            </manifestSections>
        </archive>
    </configuration>
</plugin>

In first case it is not working, variable is null. Why???

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
burtsevyg
  • 3,851
  • 2
  • 29
  • 44

1 Answers1

0

Looking at the linked github documentation, the plugin execution is bounded to the prepare-package phase, which is missing in the snippet code you posted. So probably missing the phase, it is not executed before the maven-jar-plugin and not setting the variable properly (given that its default phase should follow the default phase of the maven-jar-plugin). As such, you might get it at null.

Try to add the <phase>prepare-package</phase> element to the execution of the plugin.

Moreover, pluginConfiguration is just effectively used if the same plugin is then mentioned in the build/plugins section. Hence, in the build/plugins section you should also add as following:

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
</plugin>

It will then pick up the configuration you specified in the pluginManagement section.

From Maven documentation:

pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one. However, this only configures plugins that are actually referenced within the plugins element in the children. The children have every right to override pluginManagement definitions.

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128