Git Product home page Git Product logo

artifact-version-service's Introduction

Artifact version service

Build Status Linux GitHub release codecov

The artifact-version-service is used to find artifact versions on the classpath. It uses Javas own classloader mechanism. All "participating" jar files can contribute their own version by supplying their own implementation of the ArtifactVersionService.

This is made particularly easy by the accompanying maven plugin artifact-version-maven-plugin. Simply add this generator plugin to the maven build of your Java modules (or add it to your companies parent pom) and the service is generated automatically, keeping the artifact version up to date.

artifact-version-service is published under the MIT license. It requires at least Java 8.

Fetching all modules with coordinates

No more reading jar manifests, just a simple method call:

// iterate list of artifact dependencies
for (Artifact artifact : ArtifactVersionCollector.collectArtifacts()) {
    // print simple artifact string example
    System.out.println("artifact = " + artifact);
}

A sorted set of artifacts is returned. To modify the sorting order, provide a custom comparator:

new ArtifactVersionCollector(Comparator.comparing(Artifact::getVersion)).collect();

This way the list of artifacts is returned sorted by version numbers.

Find a specific artifact

ArtifactVersionCollector.findArtifact("de.westemeyer", "artifact-version-service");

Fetches the version details for a specific artifact.

Find artifacts with matching groupId(s)

Find all artifacts with groupId de.westemeyer (exact match):

ArtifactVersionCollector.findArtifactsByGroupId("de.westemeyer", true);

Find all artifacts where groupId starts with de.westemeyer:

ArtifactVersionCollector.findArtifactsByGroupId("de.westemeyer", false);

Sort result by version number:

new ArtifactVersionCollector(Comparator.comparing(Artifact::getVersion)).artifactsByGroupId("de.", false);

Implement custom actions on list of artifacts

By supplying a lambda, the very first example could be implemented like this:

ArtifactVersionCollector.iterateArtifacts(a -> {
    System.out.println(a);
    return false;
});

Installation

artifact-version-maven-service is available from Maven Central.

It is used in combination with the artifact-version-maven-plugin maven source code generator.

<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>

Display generated Code in your IDE

IntelliJ IDEA should show generated Java source files as soon as "Packages" perspective is selected in "Project" view.

Contributing

You have three options if you have a feature request, found a bug or simply have a question about artifact-version-service:

Development Guide

artifact-version-service 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)

artifact-version-service's People

Contributors

swesteme avatar

Stargazers

陈彦 avatar  avatar  avatar John Jetmore avatar

Watchers

 avatar

artifact-version-service's Issues

include URL

Could the library pull in project URL? I know that's kind of obscure but the first thing I wanted to use it for was to create a user agent string.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.