Specify Library Target of Maven

时光总嘲笑我的痴心妄想 提交于 2020-02-07 07:23:10

问题


How can I tell Maven to copy the dependencies into a specific location?

Side story: I am having a GWT project in Eclipse that is also a Maven Module for a larger project. This GWT project has dependencies to some libraries and I need them to be copied into <project-dir>/war/WEB-INF/lib. How can I tell Maven to do that?


Edit: I have found a way to copy a single dependency - but is there a way to copy all of them with a simple instruction?

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.10</version>
        <executions>
            <execution>
                <id>copy</id>
                <phase>package</phase>
                <goals>
                    <goal>copy</goal>
                </goals>
                <configuration>
                    <artifactItems>
                        <artifactItem>
                            <groupId>junit</groupId>
                            <artifactId>junit</artifactId>
                            <overWrite>false</overWrite>
                            <outputDirectory>${basedir}/war/WEB-INF/lib</outputDirectory>
                            <destFileName>optional-new-name.jar</destFileName>
                        </artifactItem>
                    </artifactItems>
                    <outputDirectory>${project.build.directory}/wars</outputDirectory>
                    <overWriteReleases>false</overWriteReleases>
                    <overWriteSnapshots>true</overWriteSnapshots>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>  

I have also tried this:

</dependencies>

<build>
    <outputDirectory>${project.basedir}/war/WEB-INF/classes</outputDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <!-- up to <phase>deploy</phase> -->
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.basedir}/war/WEB-INF/lib</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>

</build>

Ending up with an error saying:

Artifact has not been packaged yet. When used on reactor artifact, copy should be executed after packaging: see MDEP-187.


回答1:


It looks like you're trying to bend Maven to do things differently than what it expects you to do (e.g. here use war both as input and output folder). As a rule of thumb, never try to fight with Maven, you'll lose eventually. Follow the (almost-undocumented) Maven Way™ or just use another, more flexible tool (such as Ant+Ivy or Gradle).

If you want to use GWT with Maven from within Eclipse with the Google Plugin for Eclipse, then have a look at https://web.archive.org/web/20130619170526/https://developers.google.com/eclipse/docs/faq#gwt_with_maven and https://code.google.com/p/google-web-toolkit/wiki/WorkingWithMaven

To answer your question directly, assuming a project with <packaging>war</packaging> where you'd have changed the warSourceDirectory from its src/main/webapp default to war, then try war:inplace.
The recommended approach though (see links above) is to use war:exploded (or war:war, i.e. a simple mvn package) and run GWT DevMode using the webappDirectory, not warSourceDirectory.




回答2:


dependency:copy-dependencies should do the job.



来源:https://stackoverflow.com/questions/30631267/specify-library-target-of-maven

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!