The artifact-version-maven-plugin is used to automatically generate artifact version information to be collected by ArtifactVersionCollector somewhere in the classpath.
A more elegant way to make your Java software project aware of its module (jar) dependencies and their versions. No more reading jar manifests, just a simple service loader enabled use of:
// iterate list of artifact dependencies
for (Artifact artifact : ArtifactVersionCollector.collectArtifacts()) {
// print simple artifact string example
System.out.println("artifact = " + artifact);
}
NOTE: all participating modules need this generator plugin in their pom.xml
, so it is probably a sensible idea to create a master/parent pom.xml
for all module projects.
artifact-version-maven-plugin is published under the MIT license. It requires at least Java 8.
artifact-version-maven-plugin is available from Maven Central.
It is used in combination with the artifact-version-service runtime dependency.
<build>
<plugins>
<plugin>
<groupId>de.westemeyer</groupId>
<artifactId>artifact-version-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<goals>
<goal>generate-service</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<!-- Add source folder to Eclipse configuration. IntelliJ will recognize extra source automatically. -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/artifact-versions</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>de.westemeyer</groupId>
<artifactId>artifact-version-service</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
It is also possible to configure the generator to use target directories and a more specific service class definition:
<build>
<plugins>
<plugin>
<groupId>de.westemeyer</groupId>
<artifactId>artifact-version-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<goals>
<goal>generate-service</goal>
</goals>
</execution>
</executions>
<configuration>
<packageName>my.generated.service</packageName>
<serviceClass>MyGeneratedServiceClass</serviceClass>
<targetFolder>target/generated-sources</targetFolder>
</configuration>
</plugin>
<plugin>
<!-- Add source folder to Eclipse configuration. IntelliJ will recognize extra source automatically. -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Use artifact-version-service
s functionality like in the following example:
import de.westemeyer.version.model.Artifact;
import de.westemeyer.version.service.ArtifactVersionCollector;
public class Main {
public static void main(String[] args) {
System.out.println("List of artifacts:");
for (Artifact artifact : ArtifactVersionCollector.collectArtifacts()) {
System.out.println("artifact = " + artifact);
}
}
}
Find more examples in artifact-version-service
s description.
IntelliJ IDEA should show generated Java source files as soon as "Packages" perspective is selected in "Project" view.
You have three options if you have a feature request, found a bug or simply have a question about artifact-version-maven-plugin:
- Write an issue.
- Create a pull request. (See Understanding the GitHub Flow)
- Write an eMail to [email protected]
artifact-version-maven-plugin is built with Maven and must be compiled using JDK 8. If you want to contribute code then
- Please write a test for your change.
- Ensure that you didn't break the build by running
mvn clean verify -Dgpg.skip
. - Fork the repo and create a pull request. (See Understanding the GitHub Flow)