简体   繁体   English

如何避免父pom脱离Maven依赖关系?

[英]How to avoid parent pom from maven dependency?

My project "XYZ" needs a dependency jar , say "A.jar". 我的项目“ XYZ”需要一个依赖项jar,例如“ A.jar”。

This A.jar is having a parent pom "B.pom" (not jar), but this parent pom file is not present in repository as it is not uploaded during the release of A.jar. 此A.jar的父pom为“ B.pom”(不是jar),但是此父pom文件在存储库中不存在,因为它在A.jar发行期间未上载。

Now, when I build XYZ, it tries to download the parent "B.pom" as well along with the dependency "A.jar". 现在,当我构建XYZ时,它将尝试下载父级“ B.pom”以及依赖项“ A.jar”。 And it fails. 它失败了。 Is there any way to exclude parent pom of my dependency "A.jar" ? 有什么办法可以排除我的依赖项“ A.jar”的父pom吗? Am using Maven 3. 我正在使用Maven 3。

Thanks Rob 谢谢罗布

You can define all plugins in parent pom in pluginManagement section 您可以在pluginManagement部分的父pom中定义所有插件

<pluginManagement>
            <plugins>
                ...
                 <plugin>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.8</version>
                    <executions>
                        <execution>
                            <id>unpack-dependencies</id>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>unpack-dependencies</goal>
                            </goals>
                            <configuration>
                                <includeTypes>tar.bz2</includeTypes>
                                <outputDirectory>${project.basedir}/target/dependencies</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
              ...
            </plugins>
</pluginManagement>

And after in parent and child poms you can control the execution phase of this plugin.If you paste this in parent pom do not forget option <inherited>false</inherited> , its disable execution inheritance in child pom. 在父子poms中之后,您可以控制此插件的执行阶段。如果将其粘贴到父pom中,请不要忘记选项<inherited>false</inherited> ,该选项在子pom中禁用执行继承。

<plugins>
      <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <inherited>false</inherited>
            <executions>
                <execution>
                    <id>unpack-dependencies</id>
                    <phase>none</phase>
                </execution>
            </executions>
        </plugin>
  </plugins>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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