1

這是一個很小的項目:的Maven插件實施者和缺失的相關

<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 

validateprocess-resources

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 

我得到的錯誤有關缺少的依賴,但沒有失敗的實施者插件引起的:

[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和更高階段時可以構建項目之前首先進行檢查。

但是爲什麼達運行process-resources依賴時不檢查?

+0

你能顯示您正在使用的全部pom。 – khmarbaise

+0

已經附上完整的pom。 – zolv

+0

Outch監督。抱歉。 – khmarbaise

回答

1

很明顯,你似乎改變了出了差錯基於錯誤信息的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 

這意味着首先清理的conf/settings.xml文件。最好是使用通過安裝來的默認文件。如果您需要進行修改做到這一點在用戶的settings.xml $HOME/.m2/settings.xml或Windows C:/Users/UserName/.m2/settings.xml

除此之外,我不知道你想達到什麼樣的使用是這樣的:

[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 
+0

我已經修復了settings.xml的問題。正如我寫的 - 這與我描述的問題無關。我編輯了原始問題。 – zolv

+0

我想達到什麼是由一些財產提供其的groupId或articactId或版本或分類使用一些神器。在呈現的情況下,我想使用'$ {custom}'屬性名稱作爲分類器。 – zolv

+0

這與Maven的關係沒有意義。那是什麼目的? – khmarbaise