0

给定公司-pom 和项目结构:

   child (inherits from company-pom)
     +-- child2 (inherits from child)

当我mvn install在 child 中运行时,使用文档中的 company-pom配置,它失败了

[INFO] --- maven-enforcer-plugin:1.4:enforce (enforce-distribution) @ child ---
[DEBUG] Configuring mojo org.apache.maven.plugins:maven-enforcer-plugin:1.4:enforce from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-enforcer-plugin:1.4, parent: sun.misc.Launcher$AppClassLoader@234f79cb]
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-enforcer-plugin:1.4:enforce' with basic configurator -->
[DEBUG]   (s) fail = true
[DEBUG]   (s) failFast = false
[DEBUG]   (f) ignoreCache = false
[DEBUG]   (f) mojoExecution = org.apache.maven.plugins:maven-enforcer-plugin:1.4:enforce {execution: enforce-distribution}
[DEBUG]   (s) project = MavenProject: com.acme.maven:child:1-SNAPSHOT @ /home/egnyte/test/child/pom.xml
[DEBUG]   (s) ignoreParent = true
[DEBUG]   (s) rules = [org.apache.maven.plugins.enforcer.BanDistributionManagement@3020cc2d]
[DEBUG]   (s) session = org.apache.maven.execution.MavenSession@4a0d851e
[DEBUG]   (s) skip = false
[DEBUG] -- end configuration --
[DEBUG] Executing rule: org.apache.maven.plugins.enforcer.BanDistributionManagement
[DEBUG] distributionManagement: org.apache.maven.model.DistributionManagement@393cb70a
[DEBUG] Adding failure due to exception
org.apache.maven.enforcer.rule.api.EnforcerRuleException: You have defined a repository in distributionManagement.
        at org.apache.maven.plugins.enforcer.utils.DistributionManagementCheck.execute(DistributionManagementCheck.java:46)
        at org.apache.maven.plugins.enforcer.BanDistributionManagement.execute(BanDistributionManagement.java:87)
        at org.apache.maven.plugins.enforcer.EnforceMojo.execute(EnforceMojo.java:150)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.BanDistributionManagement failed with message:
You have defined a repository in distributionManagement.

无论我做什么,这条规则似乎在多模块项目的第一个孩子中都失败了。

试过:

  • 使 child 成为 company-pom 的模块(并mvn install从 company-pom 目录运行)

  • 明确设置ignoreParenttruefalse

用于测试的文件:./pom.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>

        <groupId>com.acme.maven</groupId>
        <artifactId>super-pom</artifactId>
        <version>1-SNAPSHOT</version>
        <packaging>pom</packaging>

        <distributionManagement>
                <repository>
                        <id>releases</id>
                        <url>https://mvnrepo.acme.com/content/repositories/releases/</url>
                </repository> 
        </distributionManagement>

        <build> 
                <plugins> 
                        <plugin>
                                <artifactId>maven-enforcer-plugin</artifactId>
                                <version>1.4</version>
                                <executions>                                     
                                        <execution>
                                                <id>enforce-distribution</id>
                                                <goals>
                                                        <goal>enforce</goal>
                                                </goals>
                                                <configuration> 
                                                        <rules>
                                                                <banDistributionManagement />
                                                        </rules>
                                                </configuration>
                                        </execution>                                     
                                </executions>
                        </plugin>
                </plugins>               
        </build> 

</project>

./child/pom.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>

        <parent>
                <groupId>com.acme.maven</groupId>
                <artifactId>super-pom</artifactId>
                <version>1-SNAPSHOT</version>
        </parent>
        <artifactId>child</artifactId>
        <packaging>pom</packaging>

        <modules>
        <module>child2</module>
        </modules>

</project>

孩子 2 ./child/child2/pom.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>

        <parent>
                <groupId>com.acme.maven</groupId>
                <artifactId>child</artifactId> 
                <version>1-SNAPSHOT</version>
        </parent>
        <artifactId>child2</artifactId> 

</project>
4

0 回答 0