2
votes

We do not have our own repository at the moment. So, when we build with maven it creates .m2 repository in the home directory of the current user.

Now there are two third party jars which are not found in the Maven Central. Suppose one of them is hasp-srm-api.jar. Today the process is this:

a. The pom.xml of the project depending on hasp-srm-api.jar contain these lines:

    <dependency>
      <groupId>com.safenet</groupId>
      <artifactId>hasp</artifactId>
      <version>1</version>
    </dependency>

b. Before doing the first build we execute the following command:

    mvn install:install-file -Dfile=hasp-srm-api.jar -DgroupId=com.safenet -DartifactId=hasp -Dversion=1 -Dpackaging=jar

My question is this - is it possible to automate this step? I would like to be able to tell maven to check whether the hasp artifact exists and if not - install it manually using the aforementioned command line. How can I do it?

3
Are you building the hasp-srm-api.jar via Maven or in other words: Do you have a pom.xml file for it?khmarbaise
I don't think it's possible with maven. You should set up an entreprise maven repository and deploy artifact on it.gontard
@khmarbaise - We are not building hasp-srm-api.jar, I think it was given to us as is by SafeNet. We could decompile and build it, not sure if this is allowed, though.mark

3 Answers

4
votes

NO. It is not possible to have maven automatically deploy an artifact into a repository in the fashion you suggest. This goes for both local and remote repositories. If the artifact exists in a some repository somewhere, you can add that repository to your build's list of known remote repos, but other than that you have to add it yourself.

You can add it to your local .m2 repository, but that will then only be good for that individual environment. Other dev's will have to repeat the process. This is one of the main attractions of running your own repository server( like Nexus ); you can add the artifact to that repository and then everyone in your organization can use it forever. There is still no way to automate the deployment of the artifact, but it's easy to do and is permanent.

Note, setting up a repository manager is very easy to do. It's highly recommended. It makes the whole Maven thing make a whole lot more sense.

0
votes

The best solution for such problems is using a repository manager which results in installing such kind of dependencies only once into the repository manager and the whole company can use it a usual dependency. That's it.

0
votes

Other option you have is to write your own maven plugin. May be below link will be right place for you start

MOJO FAQ