Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming Maven dependency in WAR's WEB-INF/lib folder

I need to have a JAR dependency in the Maven generated WAR's WEB-INF/lib folder as x-1.0.final.jar instead of x-1.0.jar, which is the name it has in the repository. What would be the best way to achieve this?

In my POM I have:

<dependency>
  <groupId>foo</groupId>
  <artifactId>x</artifactId>
  <version>1.0</version>
</dependency>

I want this to appear in the WEB-INF/lib folder as x-1.0.final.jar.

It's and external dependency on Maven Central I don't have control over. Also I don't want to force everyone using this to redeploy the dependency to their local repositories.

Is there a Maven plugin that I could utilize or should I start coding my own?

like image 318
hleinone Avatar asked Feb 11 '11 13:02

hleinone


2 Answers

You can use maven-dependency-plugin to include artifact under the name that you need.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
      <execution>
        <goals>
          <goal>copy</goal>
        </goals>
        <configuration>
          <artifactItems>
            <artifactItem>
              <groupId>foo</groupId>
              <artifactId>x</artifactId>
              <version>1.0</version>
              <type>jar</type>
              <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/lib</outputDirectory>
              <destFileName>x-1.0.final.jar</destFileName>
            </artifactItem>
          </artifactItems>
        </configuration>
      </execution>
    </executions>
</plugin>

By default, maven-dependency-plugin is bound to the process-sources phase that seems just enough for your task. Remember to set the scope provided for the artifact in dependencies so that it is not automatically included by the war plugin.

like image 124
ᄂ ᄀ Avatar answered Oct 18 '22 16:10

ᄂ ᄀ


You may want to see if the outputFileNameMapping parameter of maven war plugin can help you.

like image 25
Raghuram Avatar answered Oct 18 '22 17:10

Raghuram