我已經看到通過在模塊中構建應用程序解決了這個問題。這裏有一個很好的博客:http://giallone.blogspot.com/2012/12/maven-install-missing-offline.html?_sm_au_=iVVnK0HqJZDtb1Hw
對於你的情況,你可以有一個名爲'dependencies'的模塊,它使用maven-dependency-plugin和maven-assembly-plugin來複制所有依賴並將它們打包罐。然後,您的應用程序可以引用該jar,因爲它依賴於單獨的模塊。頂層將構建兩者。
頂層POM
.
.
.
<packaging>pom</packaging>
.
.
<modules>
<module>dependencies</module>
<module>yourApp</module>
</modules>
.
.
.
依賴性POM
.
.
.
<dependencies>
<dependency>
<groupId>some.group.id</groupId>
<artifactId>yourFirstDependency</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>some.group.id2</groupId>
<artifactId>yourSecondDependency</artifactId>
<version>1.1.4</version>
</dependency>
<dependencies>
<build>
<defaultGoal>install</defaultGoal>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
.
.
.
主應用程序POM
.
.
.
<!-- Reference your dependency module here as the first in the list -->
<dependencies>
<dependency>
<groupId>your.group.id</groupId>
<artifactId>yourDependencyJarName</artifactId>
<version>1.0</version>
</dependency>
.
.
</dependencies>
.
.
.