Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Maven enforcer插件和缺少的依赖项_Java_Maven_Dependencies_Maven Enforcer Plugin_Maven Lifecycle - Fatal编程技术网

Java Maven enforcer插件和缺少的依赖项

Java Maven enforcer插件和缺少的依赖项,java,maven,dependencies,maven-enforcer-plugin,maven-lifecycle,Java,Maven,Dependencies,Maven Enforcer Plugin,Maven Lifecycle,以下是一个最小的项目: <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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0

以下是一个最小的项目:

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.test</groupId>
    <artifactId>enforcer</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>1.3.1</version>
                <executions>
                    <execution>
                        <id>enforce-env</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <rules>
                        <requireProperty>
                            <property>custom</property>
                            <message>You must set custom property.</message>
                        </requireProperty>
                    </rules>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>com.test</groupId>
            <artifactId>enforcer-dep</artifactId>
            <version>1.0.0</version>
            <classifier>${custom}</classifier>
        </dependency>
    </dependencies>
</project>
验证正常

运行时:

mvn -Dcustom=some-value validate
mvn enforcer:enforce
或从
验证
流程资源

mvn validate
mvn initialize
mvn generate-sources
mvn process-sources
mvn generate-resources
mvn process-resources
我收到预期失败的消息:

[...]
[INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce-env) @ enforcer ---
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireProperty failed with message:
You must set custom property.
[...]
但当我运行从
compile
deploy
的任何其他(后期)阶段时,例如:

mvn install
我得到关于缺少依赖项的错误,但没有因enforcer插件而导致失败:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building enforcer 1.0.0
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.test:enforcer-dep:jar:${custom}:1.0.0 is missing, no dependency information available
Downloading: http://repo.maven.apache.org/maven2/com/test/enforcer-dep/1.0.0/enforcer-dep-1.0.0-${custom}.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.983s
[INFO] Finished at: Fri Nov 22 09:22:24 CET 2013
[INFO] Final Memory: 7M/152M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project enforcer: Could not resolve dependencies for project com.test:enforcer:jar:1.0
.0: Could not transfer artifact com.test:enforcer-dep:jar:${custom}:1.0.0 from/to central (http://repo.maven.apache.org/
maven2): Illegal character in path at index 84: http://repo.maven.apache.org/maven2/com/test/enforcer-dep/1.0.0/enforcer
-dep-1.0.0-${custom}.jar -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
在我看来,在运行
compile
和后续阶段时,似乎根本没有执行enforcer插件,或者在构建项目之前先检查依赖项


但是,为什么在运行到
进程资源时不检查依赖项呢?

显然,您似乎已更改了maven安装的设置,该设置根据错误消息出错:

[WARNING] Some problems were encountered while building the effective settings
[WARNING] expected START_TAG or END_TAG not TEXT (position: TEXT seen ...ever maven must make a connection to a remote s
erver.\n   |-->\n  <s... @111:5)  @ C:\programs\Maven\3\bin\..\conf\settings.xml

显然,您似乎已经更改了maven安装的设置,但根据错误消息,该设置出现了错误:

[WARNING] Some problems were encountered while building the effective settings
[WARNING] expected START_TAG or END_TAG not TEXT (position: TEXT seen ...ever maven must make a connection to a remote s
erver.\n   |-->\n  <s... @111:5)  @ C:\programs\Maven\3\bin\..\conf\settings.xml

你能显示你正在使用的完整pom吗?已经附加了完整pom.Outch。对不起,你能显示你正在使用的完整pom吗?已经附加了完整pom.Outch。抱歉,我已修复settings.xml的问题。正如我所写,这与我描述的问题无关。我已经编辑了原始问题。我想要实现的是通过某些属性提供其groupId或articactId或版本或分类器来使用某些工件。在本例中,我想使用
${custom}
属性名作为分类器。这在与Maven的关系中没有意义。那是为了什么?我不明白你为什么怀疑这毫无意义。如果可以在依赖项中使用像
${custom}
这样的属性,那么我认为它是有用的。如果禁止出现错误,例如“
不允许在依赖项条目中使用属性”
,那么我会理解这一点。但事实并非如此。用途例如:我有web应用程序和3台服务器。我想为每台服务器使用不同的.war包。要确定我要使用哪个属性创建
myapp-1.0-dev.war
,该属性在lib
com中具有依赖项。test:test:dev:1.0
。使用概要文件有很大的缺点这里有一个示例链接,您可以看到在依赖项中使用属性是有意义的。我已经修复了settings.xml的问题。正如我所写,这与我描述的问题无关。我已经编辑了原始问题。我想要实现的是通过某些属性提供其groupId或articactId或版本或分类器来使用某些工件。在本例中,我想使用
${custom}
属性名作为分类器。这在与Maven的关系中没有意义。那是为了什么?我不明白你为什么怀疑这毫无意义。如果可以在依赖项中使用像
${custom}
这样的属性,那么我认为它是有用的。如果禁止出现错误,例如“
不允许在依赖项条目中使用属性”
,那么我会理解这一点。但事实并非如此。用途例如:我有web应用程序和3台服务器。我想为每台服务器使用不同的.war包。要确定我要使用哪个属性创建
myapp-1.0-dev.war
,该属性在lib
com中具有依赖项。test:test:dev:1.0
。使用概要文件有很大的缺点这里有一个示例链接,您可以看到在依赖项中使用属性是有意义的。