1

Here is a minimal project:

<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>

When running:

mvn -Dcustom=some-value validate

Validation goes OK.

When running:

mvn enforcer:enforce

or any phase from validate to process-resources

mvn validate
mvn initialize
mvn generate-sources
mvn process-sources
mvn generate-resources
mvn process-resources

I get expected fail with message:

[...]
[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.
[...]

But when I run any other (later) phase from compile up to deploy e.g.:

mvn install

I get the error about missing dependency but there is no fail caused by enforcer plugin:

[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

It looks for me like enforcer plugin is not executed at all, or dependencies are checked first before project can be build when running compile and later phases.

But why dependencies are not checked when running up to process-resources?

zolv
  • 1,720
  • 2
  • 19
  • 36

1 Answers1

1

Obviously you seemed to have changed the settings of the maven installation which went wrong based on the error message:

[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

This means first clean up the conf/settings.xml file. Best is to use the default file which came via the installation. If you need to make modification do this in the users settings.xml $HOME/.m2/settings.xml or on Windows C:/Users/UserName/.m2/settings.xml

Apart from that i don't know what you like to achieve by using something like this:

[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
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • I have fixed the problem with settings.xml. As I wrote - this was not related to the problem I describe. I have edit the original question. – zolv Nov 22 '13 at 08:26
  • What I want to achieve is to use some artifact by providing its groupId or articactId or version or classifier by some property. In presented case I want to use `${custom}` property name as classifier. – zolv Nov 22 '13 at 08:30
  • Which does not make sense in relationship with Maven. What is the purpose of that? – khmarbaise Nov 22 '13 at 10:21
  • 1
    I don't understand why are You in doubt this does not make sense. If it IS possible to use properties like `${custom}` in dependencies - then I see it usefull. If it would be prohibited with error e.g. "`Using properties in dependency entries is not allowed`" then I would understand that. But it's not. Purpose e.g.: I have web application and 3 servers. I want to use different .war packages for every server. To determine which one I want to use property `${custom}` which creates `myapp-1.0-dev.war` with dependency inside lib `com.test:test:dev:1.0`. Using profiles has big disadvantages – zolv Nov 22 '13 at 21:23
  • I have already achieved such design and it works very well. Previously I was using profiles but using profiles to differ configurations per environment is bad concept. What I want to start working is enforcer. Please concentrate on this case and not on overall configuration. – zolv Nov 22 '13 at 21:26
  • 1
    Here is example link where You can see that using properties in dependencies does make sense. http://mojo.codehaus.org/gwt-maven-plugin/user-guide/using-different-gwt-sdk-version.html – zolv Nov 22 '13 at 22:43