简体   繁体   中英

copy dependencies in a spring boot application

I have spring boot application where during maven install, I want it to create a jar and copy the dependencies into a lib folder. I am trying to use these two maven plugins that are working fine in other maven projects but doesn't work in a spring boot application.

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
           <useDefaultManifestFile>true</useDefaultManifestFile>
           <archive>
              <manifest>
                 <addClasspath>true</addClasspath>
                 <mainClass>xxx.Main</mainClass>
                 <classpathPrefix>lib/</classpathPrefix>
              </manifest>
           </archive>
        </configuration>
     </plugin>
     <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
           <execution>
              <phase>install</phase>
              <goals>
                 <goal>copy-dependencies</goal>
              </goals>
              <configuration>
                 <outputDirectory>${project.build.directory}/lib</outputDirectory>
              </configuration>
           </execution>
        </executions>
     </plugin>

What is happening is that the jar gets created even if the maven-jar-plugin is omitted. And it doesn't do anything with the maven-dependency-plugin. So it pretty much ignores both these plugins.

I put the Spring Boot plugin after copy-dependencies and work fine!

<plugin>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

Notes: I clean Maven repository to work!

I think you should try Spring boot + Gradle: Spring boot Gradle

In build.gradle file, you can customize the build process and copy your dependencies into lib folder by using gradle copy method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM