18

(Please read at least this before answering: This is a temporary measure! No, we do not want to set up a local repository manager and manually run a script)

We have a legacy project with a few dependencies which we have a local copy of including source and javadoc, and which has been proven to work well in production, but which is not available in the same quality in Central. We want to use those jars we already have.

I have found that I can manually run a suitably complex mvn install:install-file command to get the artifacts injected in the repository of the local machine, but I would like to have it work as part of the normal maven build of our various modules.

Given I have an otherwise blank module containing multiple jars which each need to be inserted with an install:install-file how should I do this in my pom.xml to be fully conformant with the normal Maven build?

Or can I just attach multiple jars to be the output of the module and somehow attach javadoc and source too)?

(and, please, no suggestion about submitting to central or setting up a local repository manager. This is a temporary solution until we have an opportunity to upgrade to a newer version of the dependencies)

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • you want the install to run with every build of the project? isn't the local installation a one time thing? – jtahlborn May 29 '12 at 15:57
  • I would guess it could create a pom artifact and only be updated when the artifact changes? But if it is necessary for this, that would be acceptable for now. – Thorbjørn Ravn Andersen May 29 '12 at 16:32
  • See [this answer](https://stackoverflow.com/a/48670812/1744774) to [I want to load all JARs from my libs project folder with Maven](https://stackoverflow.com/q/48665906/1744774) for avoiding that the `install-plugin` runs at every build. – Gerold Broser Feb 07 '18 at 21:43
  • @GeroldBroser I strongly dislike Maven profiles. Anything that needs to be documented with "Remember to ..." is a problem waiting to happen. – Thorbjørn Ravn Andersen Dec 27 '18 at 00:30

1 Answers1

21

I would imagine something like this would work (this will install it on every build):

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-install-plugin</artifactId>
            <executions>
                <execution>
                    <id>inst_1</id>
                    <phase>initialize</phase>
                    <goals>
                        <goal>install-file</goal>
                    </goals>
                    <configuration>
                        <!-- config for file 1 -->
                    </configuration>
                </execution>
                <execution>
                    <id>inst_2</id>
                    <phase>initialize</phase>
                    <goals>
                        <goal>install-file</goal>
                    </goals>
                    <configuration>
                        <!-- config for file 2 -->
                    </configuration>
                </execution>
                <!-- execution file 3... -->
            </executions>
        </plugin>            
    </plugins>
</build>
jtahlborn
  • 52,909
  • 5
  • 76
  • 118
  • 2
    I believe there is an error in this answer. `initialize` had to be changed to `install` for me in Eclipse Luna. Otherwise Eclipse would flag it as an invalid lifecycle – medge Dec 11 '14 at 18:19
  • "mvn initialize" puts the jars into the local maven repository but not the "mvn install". Why ? – signonsridhar Nov 14 '16 at 22:52
  • Thanks. For some of us dealing with legacy or transitional projects, the limitations of dependencies, and the prohibition of relative paths in a project hierarchy (all of our libraries are in ${project_root}/lib/** locations), are a terrible annoyance. Eventually they will disappear, but this is a great intermediate solution. Again, thank you. – K Markey May 03 '13 at 18:55