4

I am developing a maven plugin , I have a parameter called "FinalVersion" which is created as a @Parameter in Mojo and its value is being set in Mojo class. I need to pass "finalversion" to my pom file and use it as an element in the configuration of other plugin. like this:

@Mojo(name = "validate", defaultPhase = LifecyclePhase.COMPILE)
public class VersionValidatorMojo extends AbstractMojo{
    .
    .

    @Parameter(property = "finalVersion")
    private String finalVersion ;

and I want to have something like this in my pom.xml

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>custom-maven-release-plugin</artifactId>
                <configuration>
                    <goals>release</goals>
                    <version>finalversion</version>
                </configuration>
            </plugin>

ALSO in my scenario I have the project version set by developer and not getting from SCM, which plugin can I use?

Bests

frdsprtrdr
  • 384
  • 1
  • 2
  • 11
  • 1
    Using a configuration of one plugin within an other is in general a bad idea...this will couple plugins together...The question is: What kind of problem are you trying to solve? Also I would take a look https://maven.apache.org/maven-ci-friendly.html – khmarbaise Feb 07 '20 at 10:24
  • thanks @khmarbaise , I have a single project setup and I do not get version from CI .in fact I gave the version manually and then it is being calculated and is outputted as finalversion which should be used in pom again. – frdsprtrdr Feb 13 '20 at 12:34

1 Answers1

0

your POM should use the finalVersion tag

            <configuration>
                <finalversion>X.Y</finalversion>
            </configuration>

Here is another full example with a parameter called locations

        <plugin>
            <groupId>mygroup</groupId>
            <artifactId>myapp</artifactId>
            <version>${project.version}</version>
            <configuration>
                <locations>
                    <param>${basedir}/src/main/resources/db/toBeIncluded</param>
                    <param>${basedir}/src/main/resources/db/migration/upgrade</param>
                </locations>
            </configuration>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>validate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

In my Mojo implementation I have then defined

    @Parameter
    private String[] locations;
Beppe C
  • 11,256
  • 2
  • 19
  • 41
  • Thanks but I do not need to change the "finalversion" in my pom, I just need to use it as an input for another plugin. in fact I only setup the finalversion in my mojo and it is readonly. any suggestions? – frdsprtrdr Feb 13 '20 at 12:29
  • Thats what I am suggesting, I have provided an example based on your code. In my project I have the following for example mygroup myapp ${project.version} ${basedir}/src/main/resources/path where locations is a @Parameter in my Mojo impl – Beppe C Feb 13 '20 at 13:14
  • and now imagine you have to use your "location" parameter in a part of your pom.xml how can we do it? – frdsprtrdr Feb 13 '20 at 13:19
  • I have elaborated the answer, hope we are getting closer – Beppe C Feb 13 '20 at 13:59