Maven插件依赖项包含在MANIFEST.MF中

时间:2014-07-07 12:17:15

标签: java eclipse maven

我试图在Eclipse-IDE(Version Kepler Service Release 2; Maven 3.0.4)的MANIFEST.MF中构建一个带有有效Classpath的jar。我的pom.xml中maven-jar-plugin的相关配置是

<plugin>
  <artifactId>maven-jar-plugin</artifactId>
  <version>2.4</version>
  <configuration>
    <archive>
      <addMavenDescriptor>false</addMavenDescriptor>
      <manifest>
        <addClasspath>true</addClasspath>
        <classpathPrefix>lib/</classpathPrefix>
        <classpathLayoutType>custom</classpathLayoutType>
        <customClasspathLayout>$${artifact.artifactId}-$${artifact.version}.$${artifact.extension}</customClasspathLayout>
      </manifest>
    </archive>
  </configuration>
</plugin>

然而,这不能按预期工作。例如,我使用findbugs-maven-plugin,这个插件创建了一些Maven-Dependencies,即我本地存储库中的findbugs-maven-plugin-2.5.4.jar。下面是findbugs-plugin的配置

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>findbugs-maven-plugin</artifactId>
  <version>2.5.4</version>
  <configuration>
    <findbugsXmlOutput>true</findbugsXmlOutput>
    <xmlOutput>true</xmlOutput>
    <!-- Optional directory to put findbugs xdoc xml report -->
    <xmlOutputDirectory>target/findbugs</xmlOutputDirectory>
  </configuration>
 </plugin>

这没关系,但是这个依赖项也使它在我的MANIFEST.MF的classpath-entry中看起来像这样(摘录):

lib/findbugs-maven-plugin-2.5.4.jar

问题是,我不知道如何禁用此行为。

到目前为止我尝试了什么: 使用maven-dependency-plugin并定义excludeGroupId和excludeArtifactId条目,这解决了另一个问题,其中所有依赖项都复制到了target-Directory中的lib-Folder。

显然我在这里遗漏了一些东西。

1 个答案:

答案 0 :(得分:2)

好的,我设法解决了这个问题。

依赖来自我正在处理的模块库以及哪个模块库。它定义了对findbugs-maven-plugin-2.5.4.jar的依赖。这种依赖性被maven识别并放在我想要构建的jar的类路径中。

可以在http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html找到此问题的解决方案。可以定义传递库的排除。因此,必须将依赖于我的模块的依赖写为:

<dependency>
  <groupId>base</groupId>
  <artifactId>base</artifactId>
  <version>1.0.0</version>
  <exclusions>
    <exclusion>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>findbugs-maven-plugin</artifactId>
    </exclusion>
  </exclusions>
</dependency>

感谢Tome,他最终指出了我正确的方向!

相关问题