我有两个名为 Utilities 和 Campaigns 的独立 Maven 项目。我的实用程序项目有依赖项。Campaigns 项目需要执行 Utilities 中类内的 main 方法。为了实现这一点,我一直在使用 exec-maven-plugin。使用此插件,我可以从我的 Campaigns pom 文件执行依赖项(实用程序)的主要方法。但是,当我执行该方法时,实用程序的传递依赖性似乎并未解决。我可以通过向两个 pom 文件添加相同的依赖项来解决这个问题,但如果可能的话,我想避免这种冗余,而只是从实用程序继承。我在下面包含了我的 Campaign pom 文件的插件部分。这有点令人困惑,但是有没有一种方法可以解决这个问题,而不必定义相同的依赖项?无需在插件部分列出依赖项?
主要方法位于 com.sample.generics.Login.java 中。
活动.pom
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.sample.generics.Login</mainClass>
<classpathScope>test</classpathScope>
<arguments>
<argument>${resourcesDir}</argument>
<argument>${settingsFile}</argument>
</arguments>
<includeProjectDependencies>true</includeProjectDependencies>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
您还可以考虑在实用程序项目中创建一个可执行 jar。请参阅https://www.baeldung.com/executable-jar-with-maven之类的内容。然后,这个可执行 jar 可以包含您拥有的所有依赖项。(例如,确保它存在于具有不同分类器的常规 jar 旁边)然后您可以在 exec-maven 中执行它。
或者,在 Utilities 构建中,您可以将所有 Utilities 依赖项复制到单独的目录(例如 /target/deps)(请参阅 maven 依赖项插件,https: //maven.apache.org/plugins/maven-dependency- plugin/examples/copying-project-dependency.html ) ,并将该目录添加到 exec maven 的类路径中
| 归档时间: |
|
| 查看次数: |
723 次 |
| 最近记录: |