Maven get properties at compile time

How can we get Maven properties in the source file at compile time

pom.xml

<artifactId>myApp</artifactId>
<version>1.0.0</version>

Main.java

public class Main {
  private static final String artifactId = "project.artifactId";
  private static final String version = "project.version";
}

Is hard cod in the classroom possible?

+2
source share
2 answers

You can use the maven property to create the java source file in the generate-src directory and attach it via the build helper maven plugin to the list of source folders.

You will manage the contents of the java file.

One way to create the original java file is to use the groovy maven plugin with an attachment.

+1
source

The question is not completely repeated, but the answer I gave there explains how you can do this.

Generate Version.java file in Maven

0
source

All Articles