This guide will walk you through the process of creating a Java library in a Maven project, push a built artifact to Gemfury, and then import it as a dependency in another Maven project.
Before you get started, be sure you have the following:
Local Maven installation (3.3.1+) Gemfury account Maven is a project management tool, commonly used in the Java ecosystem. It can be used to specify project information for Java libraries, so the library can easily be linked in other Maven projects.
To get started in creating your Java library, initialize your Maven project with mvn archetype:generate:
$ mvn archetype:generate -DgroupId=com.mycompany.foo -DartifactId=foolib \ -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 \ -DinteractiveMode=false $ cd foolib Please take note to use your own values for groupId and artifactId.
This command will create an initial pom.xml file to describe your project. The file will contain the project’s name and its dependencies.
At this point, you may customize the generated pom.
Now that you have created your Java library, you can now push the generated artifact into your Gemfury account. To do that, you can use the Maven deploy function.
Configure Maven project First, you will need to configure your Maven project. Add a new repository entry in the distributionManagement section on the pom.xml of your project with your Repository URL. The distributionManagement tag should be a direct child of your project tag.
Now that you have uploaded the artifact containing your Java library in your Gemfury account, you can use your library as a dependency in a Maven project.
To use your library, you can reference the artifact as a dependency in your project’s pom.xml.
<project xmlns=...> ... <dependencies> <dependency> <groupId>com.mycompany.foo</groupId> <artifactId>foolib</artifactId> <version>1.0-SNAPSHOT</version> <scope>test</scope> </dependency> </dependencies> ... </project> Next, you will need to add your Gemfury account Maven’s repository, so Maven can find the artifact.