Maven - Reactors (Aggregation) - maven

I have a maven project with a following directory structure:
trunk
| pom.xml
| coreutils
| | pom.xml
| | src
| budgetCap
| | pom.xml
| | src
The content of trunk/pom.xml is :
<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
hxttp://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Ant2Maven</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>Parent Pom</name>
<modules>
<module>coreutils</module>
<module>budgetCap</module>
</modules>
In this structure, "budgetCap" is dependent on "coreutils",i.e. pom.xml of "budgetCap" contains a dependency of "coreutils"
Now I have two methods to build this project
First Method
Aggregation using Reactor
I will be inside trunk
So first of all I do mvn clean
shakim:trunk shakim.md$ mvn clean
Maven deletes the target folder of the two module in this order:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] coreutils
[INFO] budgetCap Maven Webapp
[INFO] Parent Pom
Now when i do mvn install
shakim:trunk shakim.md$ mvn install
Maven starts building modules in the following order:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] coreutils
[INFO] budgetCap Maven Webapp
[INFO] Parent Pom
In the given order, coreutils gets installed in the local repository successfully.
But budgetCap fails at the compilation giving an error that maven is unable to locate a class which was supposed to be produced by coreutils
the error message is as follows:
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building budgetCap Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # budgetCap ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # budgetCap ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 65 source files to /Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/target/classes
[INFO] -------------------------------------------------------------
[WARNING] COMPILATION WARNING :
[INFO] -------------------------------------------------------------
[WARNING]/Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/core/SingletonAggregator.java: /Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/core/SingletonAggregator.java uses unchecked or unsafe operations.
[WARNING]/Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/core/SingletonAggregator.java: Recompile with -Xlint:unchecked for details.
[INFO] 2 warnings
[INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/core/BudgetCapServer.java:[41,34] package com.adiquity.request.utils does not exist
[ERROR] /Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/utils/Utils.java:[9,34] package com.adiquity.request.utils does not exist
[ERROR] /Users/shakim.md/shakim/maven/ops/adq_services/trunk/budgetCap/src/main/java/com/adiquity/budgetCap/log/data/parser/ConversionParser.java:[16,34] package com.adiquity.request.utils does not exist
Briefly speaking this package package com.adiquity.request.utils is actually present in coreutils, which this module budgetCap must have located successfully, but it is not.
Second Method
Go inside coreutils and do a
shakim:coreutils shakim.md$ mvn clean install
Go inside budgetCap and do a
shakim:budgetCap shakim.md$ mvn clean install
budgetCap compiles successfully without reporting any kind of error.
My question is that I want to use Reactors in Maven and I am unable to figure out why the build fails on using 1st method whereas 2nd method of building completes smoothly??
I am not sure how to use reactors, do we need to include anything in pom of coreutils and budgetCap signifying that pom of trunk is the parent.
Note: I don't want to use inheritance in this project

Related

How to ask maven-assembly-plugin to skip (ignore) missing resources and not to stop build?

I am trying to build Metasfresh ERP backend (server-side) suite https://github.com/metasfresh/metasfresh/tree/master/backend and my maven build stops at the project https://github.com/metasfresh/metasfresh/tree/master/backend/de.metas.adempiere.adempiere/migration because of missing resrouces required by the maven-assembly-plugin.
Specifically, the maven log says:
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # de.metas.adempiere.adempiere.migration-sql ---
[INFO] Building jar: C:\Workspace-Brugere\metasfresh\backend\de.metas.adempiere.adempiere\migration\target\de.metas.adempiere.adempiere.migration-sql-10.0.0.jar
[INFO]
[INFO] --- maven-assembly-plugin:3.0.0:single (make-postgresql-assembly) # de.metas.adempiere.adempiere.migration-sql ---
Downloading: https://repository.apache.org/snapshots/de/metas/metasfresh-assemblies/maven-metadata.xml
Downloading: https://repo.metasfresh.com/repository/mvn-master/de/metas/metasfresh-assemblies/maven-metadata.xml
Downloaded: https://repo.metasfresh.com/repository/mvn-master/de/metas/metasfresh-assemblies/maven-metadata.xml (8.7 kB at 5.5 kB/s)
Downloading: https://repo.metasfresh.com/repository/mvn-master/de/metas/de.metas.parent.general/5.159.1-21669+master/de.metas.parent.general-5.159.1-21669+master.pom
Downloading: https://repo.metasfresh.com/repository/mvn-master/de/metas/de.metas.parent.general/5.159.1-21672+master/de.metas.parent.general-5.159.1-21672+master.pom
Downloading: https://repo.metasfresh.com/repository/mvn-master/de/metas/de.metas.parent.general/5.159.1-21673+master/de.metas.parent.general-5.159.1-21673+master.pom
...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] de.metas.parent .................................... SUCCESS [ 2.944 s]
...
[INFO] de.metas.monitoring ................................ SUCCESS [ 10.034 s]
[INFO] de.metas.adempiere.adempiere.patched-ecs ........... SUCCESS [ 13.617 s]
[INFO] de.metas.adempiere.adempiere.migration-sql ......... FAILURE [ 36.118 s]
[INFO] metasfresh-report .................................. SKIPPED
...
[INFO] metasfresh-dist-dist ............................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 04:36 min
[INFO] Finished at: 2020-12-25T19:01:04+02:00
[INFO] Final Memory: 146M/1207M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:3.0.0:single (make-postgresql-assembly)
on project de.metas.adempiere.adempiere.migration-sql:
Execution make-postgresql-assembly of goal org.apache.maven.plugins:maven-assembly-plugin:3.0.0:single failed:
Plugin org.apache.maven.plugins:maven-assembly-plugin:3.0.0 or one of its dependencies could not be resolved:
Failed to collect dependencies at org.apache.maven.plugins:maven-assembly-plugin:jar:3.0.0 ->
de.metas:metasfresh-assemblies:jar:5.159.1-21669+master:
Failed to read artifact descriptor for de.metas:metasfresh-assemblies:jar:5.159.1-21669+master:
Could not find artifact de.metas:de.metas.parent.general:pom:5.159.1-21669+master in metasfresh-repo
(https://repo.metasfresh.com/repository/mvn-master/) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
I checked and the maven-assembly-plugin reads resources from the
https://repo.metasfresh.com/repository/mvn-master/de/metas/metasfresh-assemblies/maven-metadata.xml
and it have entry for 5.1159.1-21669+master:
<version>5.159.1-21667+master</version>
<version>5.159.1-21668+master</version>
<version>5.159.1-21669+master</version>
<version>5.159.1-21670+master</version>
<version>5.159.1-21671+master</version>
<version>5.159.1-21672+master</version>
<version>5.159.1-21673+master</version>
<version>5.159.1-21674+master</version>
but there is no entry at link https://repo.metasfresh.com/repository/mvn-master/de/metas/de.metas.parent.general/5.159.1-21669+master/de.metas.parent.general-5.159.1-21669+master.pom
So - this is very strange thing with this project. Maybe there are some administrative/commercial/organizational issues in this open source project and they are keeping forbidden some necessary files intentionally.
My question is - how can I ask maven plugins to skip missing resources? And just see what is happening?
Maybe I can download maven-metadata.xml, remove the entries for which there are no versions and then hope that maven-assembly-plugin will use local (handcrafted) mave-metadata.xml?
de.metas:metasfresh-assemblies:jar:5.159.1-21669+master's POM contains:
...
<parent>
<groupId>de.metas</groupId>
<artifactId>de.metas.parent.general</artifactId>
<version>5.159.1-21669+master</version>
...
</parent>
...
but, as you found, there is no such artifact.
This is also not a resource (as in src/[main|test]/resources), but a parent POM. You can't "skip" parent POMs, i.e. you can't build child POMs if the parent is not available. This is like trying to compile a sub-class if the super-class isn't available in the classpath.

Downloading ear file from nexus using maven dependency plugin get goal

I am using the maven dependency plugin get goal to download an artefact from nexus. I can use it to download jar as per below
mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get -DrepoUrl=http://nexus.url/nexus/content/groups/public-all/ -Dartifact=groupId:artifactId:version:jar -Dtransitive=false -Ddestination=/my/path
To download a war I can use
mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get -DrepoUrl=http://nexus.url/nexus/content/groups/public-all/ -Dartifact=groupId:artifactId:version:war -Dtransitive=false -Ddestination=/my/path
I am however failing to download an ear using the following
mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get -DrepoUrl=http://nexus.url/nexus/content/groups/public-all/ -Dartifact=groupId:artifactId:version:ear -Dtransitive=false -Ddestination=/my/path
The output of the above command is as per below
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:get (default-cli) # standalone-pom ---
[INFO] Resolving groupId:artifactId:ear:version
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.797 s
[INFO] Finished at: 2017-10-20T13:31:02+02:00
[INFO] Final Memory: 7M/19M
[INFO] ------------------------------------------------------------------------
I have confirmed that the ear is indeed present in Nexus. The above command runs successfully but the ear is not actually downloaded.
What is wrong with the above command to download the ear? How can I download an ear file from Nexus using the mvn command?
Do note that I have replaced the actual groupId, artifactId and versions in the code above with their respective words.

Javac does not compile classes to target folder

YES I did mvn clean.
Tried in Maven 3.1.0, 3.0.4 and 3.0.3
My multi-module maven project's build (mvn install) fails at some module. The cause is that the last module was built with SUCCESS, but in fact the jar is empty. And then the next module can't find the classes that it needs to see.
[INFO] Reactor Summary:
[INFO]
[INFO] myproject ......................................... SUCCESS [0.309s]
[INFO] myproject-service ................................. SUCCESS [0.011s]
[INFO] myproject-service-api ............................ SUCCESS [1.242s]
[INFO] myproject-service-spi ............................ FAILURE [1.422s]
[INFO] myproject-datap-lib-impl .................. SKIPPED
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.746s
[INFO] Finished at: Wed Jul 24 17:30:57 EEST 2013
[INFO] Final Memory: 62M/919M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project myproject-service-spi: Compilation failure: Compilation failure:
[ERROR] C:\dev\mything\myproject\trunk-checkout2\service\spi\src\main\java\org\myself\service\spi\validation\fake\AbstractConfigurableFakeDetector.java:[12,55] error: package org.myself.service.validation.fake does not exist
Here is the complete debug output from running mvn -X clean install -amd -Dmaven.test.skip=true > build.log http://nopaste.info/7f07571993.html
In IntelliJ IDEA it all looks good, the class exists.
Not just the generated jar is empty, also the folder service/api/target/classes.
My pom file for service-api is very basic, just like the others that work:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>myparent</artifactId>
<groupId>my.parent</groupId>
<version>myversion</version>
</parent>
<groupId>myproject.service.api</groupId>
<artifactId>myproject-service-api</artifactId>
<dependencies>
... some local and external dependencies
</dependencies>
<properties>
</properties>
</project>
No maven plugins here.
I don't think I have a cyclic dependency, because Maven 3 would detect this.
UPDATE
I've now got it down to this: a simple mvn compile on the module that creates the empty jar gives me this output in IntelliJ IDEA:
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building myproject-service-api 4.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # myproject-service-api ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\myproject\trunk-checkout2\service\api\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # myproject-service-api ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 217 source files to C:\myproject\trunk-checkout2\service\api\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.908s
[INFO] Finished at: Wed Jul 24 21:56:49 EEST 2013
[INFO] Final Memory: 20M/232M
[INFO] ------------------------------------------------------------------------
And right after running that, the folder C:\myproject\trunk-checkout2\service\api\target\classes is empty. So the 217 Java classes are detected, maven says it compiles them and puts them into my target folder, but it does not.
Update 2
I've compared the output of mvn -X compile of a module that works compared to this one (remember, all end in BUILD SUCCESS but this one has an empty target folder). There is a difference: the failing one lists all java files as "Stale source detected".
[DEBUG] Using compiler 'javac'.
[DEBUG] Source directories: [C:\myproject\trunk-checkout2\service\api\src\main\java]
[DEBUG] Classpath: [C:\myproject\trunk-checkout2\service\api\target\classes
... all the dependency jars
[DEBUG] Output directory: C:\myproject\trunk-checkout2\service\api\target\classes
[DEBUG] CompilerReuseStrategy: reuseCreated
[DEBUG] useIncrementalCompilation enabled
[DEBUG] Stale source detected: C:\dev\myproject\trunk-checkout2\service\api\src\main\java\my\Class.java
... listing all 217 classes
[INFO] Changes detected - recompiling the module!
[DEBUG] Classpath:
[DEBUG] C:\myproject\trunk-checkout2\service\api\target\classes
... all the dependency jars
[DEBUG] Source roots:
[DEBUG] C:\myproject\trunk-checkout2\service\api\src\main\java
[DEBUG] Command line options:
[DEBUG] -d (...) -g -nowarn -target 1.6 -source 1.6 -encoding UTF-8
[DEBUG] incrementalBuildHelper#beforeRebuildExecution
[INFO] Compiling 217 source files to C:\myproject\trunk-checkout2\service\api\target\classes
[DEBUG] incrementalBuildHelper#afterRebuildExecution
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.060s
[INFO] Finished at: Wed Jul 24 23:16:37 EEST 2013
[INFO] Final Memory: 22M/328M
[INFO] ------------------------------------------------------------------------
I've seen this bug report https://jira.codehaus.org/browse/MCOMPILER-205 and I do have package-info.java files in this module, but I've tried a pre-3 compiler plugin, same result. And I've tried with an annotation as described there, no luck either. So I don't think it's the same case.
I don't have a public static void main, thus this bug Workaround for javac compilation order bug in maven can't be it.
UPDATE 3
There's an abort in javac, without notice (-verbose turned on). Just 1 class works, all 217 fails. So I guess I have to try to find which causes it, etc... will post again.
First in your log output there are several hints about things like ${version} which you should fix furthermore there are other warnings about duplicate definitions of dependencies etc.
I have taken a deeper look into the log output:
[ERROR] C:devmythingmyprojecttrunk-checkout2servicespisrcmainjavaorgmyselfservicespivalidationfakeAbstractConfigurableFakeDetector.java:[12,55] error: package org.myself.service.validation.fake does not exist
[ERROR] C:devmythingmyprojecttrunk-checkout2servicespisrcmainjavaorgmyselfservicespivalidationfakeAbstractConfigurableFakeDetector.java:[13,55] error: package org.myself.service.validation.fake does not exist
[ERROR] C:devmythingmyprojecttrunk-checkout2servicespisrcmainjavaorgmyselfservicespivalidationfakeAbstractConfigurableFakeDetector.java:[82,14] error: cannot find symbol
[ERROR] symbol: class SimpleValidationResult
location: class AbstractConfigurableFakeDetector
C:devmythingmyprojecttrunk-checkout2servicespisrcmainjavaorgmyselfservicespivalidationfakeAbstractConfigurableFakeDetector.java:[106,66] error: cannot find symbol
[ERROR] symbol: class FakeType
location: class AbstractConfigurableFakeDetector
C:devmythingmyprojecttrunk-checkout2servicespisrcmainjavaorgmyselfservicespivalidationfakeAbstractConfigurableFakeDetector.java:[97,8] error: cannot find symbol
[ERROR] symbol: class SimpleValidationResult
location: interface SomethingThatReturnsValidationResult
C:devmythingmyprojecttrunk-checkout2servicespisrcmainjavaorgmyselfservicespigenderresultAverageComputedGenderResultCollector.java:[4,46] error: package org.myself.service.gender does not exist
[ERROR] C:devmythingmyprojecttrunk-checkout2servicespisrcmainjavaorgmyselfservicespigenderresultAverageComputedGenderResultCollector.java:[5,46] error: package org.myself.service.gender does not exist
[ERROR] C:devmythingmyprojecttrunk-checkout2servicespisrcmainjavaorgmyselfservicespigenderresultAbstractAverageGenderCollector.java:[4,46] error: package org.myself.service.gender does not exist
[ERROR] C:devmythingmyprojecttrunk-checkout2servicespisrcmainjavaorgmyselfservicespigenderresultAverageComputedGenderResultCollector.java:[31,29] error: cannot find symbol
[ERROR] symbol: class ComputedGenderResult
location: class AverageComputedGenderResultCollector
which gives me the impression that you are using test classes or may be package names from the test area which will not work or you are missing a dependency to an other package.
The cause was due to a bug in javac. Some valid syntax it could not handle. That then generated the empty jar, and so on.

org.codehaus.mojo:properties-maven-plugin:1.0-alpha-2 error

I have the following Maven project structure:
xyz
|
-props
| |
| - root.properties
|
-module_a
| |
| -pom.xml
|
-pom.xml
My root artifact defines a child module (module_a) and this is referencing the parent artifact.
In the root pom.xml I am reading a property file from the common props folder using the
org.codehaus.mojo:properties-maven-plugin:1.0-alpha-2 plugin.
When I issue the
mvn clean package
command I get the following putput:
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] my_artifact
[INFO] module_a
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my_artifact 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) # my_artifact ---
[INFO]
[INFO] --- properties-maven-plugin:1.0-alpha-2:read-project-properties (default) # my_artifact ---
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building module_a 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) # module_a ---
[INFO]
[INFO] --- properties-maven-plugin:1.0-alpha-2:read-project-properties (default) # module_a ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] my_artifact ....................................... SUCCESS [0.234s]
[INFO] module_a .......................................... FAILURE [0.000s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.344s
[INFO] Finished at: Thu Aug 09 15:37:46 CEST 2012
[INFO] Final Memory: 2M/5M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:properties-maven-plugin:1.0-alpha-2:read-project-properties (default) on project module_a: Properties file not found: G:\java\xyz\module_a\props\root.properties -> [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/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :module_a
In the child module Maven tries to read the property file from an inexistetnt subfolder. Can anybody help me solve this?
Thank you
When maven evaluates the pom files and creates the effective poms ( aggregated with inheritance) some properties are excluded from being inherited. These are the ones starting with project.* and therefore also the project.basedir. Thats why you cannot define the property from where the property file is being loaded in the parent.
The reason for this behaviour is isolation. Every module should be isolated from everything but the maven repository. Even using the settings.xml profiles violates this invariant and you loose the portability of builds.
This invariant is not necessary in many cases so if you have many modules and you want to use one property file, what you can do is:
define a property e.g. "filters.dir" in your root pom to ${project.basedir}/src/main/filters
configure the plugin to load a property file from ${filters.dir}/my.properties
in any submodule you can now override filters.dir to ../src/main/filters
if you have many submodules you can define a wrong path "../src/main/filters" for filters.dir in the root and then you don't need to define the property in any submodule. To prevent the build from failing you need to set the plugin to ignore failures.
An alternative would be to write a maven extension by extending AbstractMavenLifecycleParticipant and load the property file there using the maven api to determine the root directory of your project.
I have face a similar issue.
I have a parent project pom.xml which has a build.properties file
the parent project has several modules.
When I created a new module, and wanted to build the whole parent project, I got:
[ERROR] Failed to execute goal org.codehaus.mojo:properties-maven-plugin:1.0-alpha-2:read-project-properties (default) on project attachment-services: Properties file not found: /home/raz/git/parent/attachment-services/build.properties -> [Help 1]
To fix this, I have added in the new module's pom.xml the following
<properties>
<build.properties.location>..</build.properties.location>
</properties>
and of course, this build.properties.location was already defined in the parent pom, like:
<properties>
<build.properties.location>${project.basedir</build.properties.location
</properties>

Maven - Different Dependency Version in Test

I'm suffering an issue similar to Maven 2 - different dependency versions in test and compile but the specified answer there does not work.
In my project I need to depend on a Cloudera distribution of Hadoop and a 'vanilla' version for JUnit testing, as the former only works on *nix.
When I try and execute my application, I get Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/conf/Configuration. When I run JUnit tests from Maven or Eclipse, everything works fine. If I comment out the test dependencies, the application runs successfully.
Why is the compile dependency getting ignored when the test dependency is uncommented?
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>0.20.2-cdh3u2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-test</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
mvn dependency:list is shown below. The compile scoped version does not show up at all:
[INFO] The following files have been resolved:
[INFO] ant:ant:jar:1.6.5:test
[INFO] aopalliance:aopalliance:jar:1.0:compile
[INFO] asm:asm:jar:3.3.1:compile
[INFO] cglib:cglib:jar:2.2.2:compile
[INFO] ch.qos.logback:logback-classic:jar:1.0.0:compile
[INFO] ch.qos.logback:logback-core:jar:1.0.0:compile
[INFO] com.google.guava:guava:jar:r08:compile
[INFO] com.h2database:h2:jar:1.3.164:test
[INFO] com.jolbox:bonecp:jar:0.7.1.RELEASE:compile
[INFO] com.sun.jersey:jersey-core:jar:1.11:test
[INFO] commons-beanutils:commons-beanutils:jar:1.7.0:test
[INFO] commons-beanutils:commons-beanutils-core:jar:1.8.0:test
[INFO] commons-cli:commons-cli:jar:1.2:test
[INFO] commons-codec:commons-codec:jar:1.4:test
[INFO] commons-collections:commons-collections:jar:3.2.1:test
[INFO] commons-configuration:commons-configuration:jar:1.6:test
[INFO] commons-digester:commons-digester:jar:1.8:test
[INFO] commons-el:commons-el:jar:1.0:test
[INFO] commons-httpclient:commons-httpclient:jar:3.0.1:test
[INFO] commons-lang:commons-lang:jar:2.4:test
[INFO] commons-logging:commons-logging:jar:1.1.1:compile
[INFO] commons-net:commons-net:jar:1.4.1:test
[INFO] hsqldb:hsqldb:jar:1.8.0.10:test
[INFO] junit:junit:jar:4.10:test
[INFO] mysql:mysql-connector-java:jar:5.1.18:compile
[INFO] net.java.dev.jets3t:jets3t:jar:0.7.1:test
[INFO] net.sf.kosmosfs:kfs:jar:0.3:test
[INFO] org.apache.commons:commons-math:jar:2.1:test
[INFO] org.apache.ftpserver:ftplet-api:jar:1.0.0:test
[INFO] org.apache.ftpserver:ftpserver-core:jar:1.0.0:test
[INFO] org.apache.ftpserver:ftpserver-deprecated:jar:1.0.0-M2:test
[INFO] org.apache.hadoop:hadoop-core:jar:1.0.0:test
[INFO] org.apache.hadoop:hadoop-test:jar:1.0.0:test
[INFO] org.apache.mina:mina-core:jar:2.0.0-M5:test
[INFO] org.codehaus.jackson:jackson-core-asl:jar:1.0.1:test
[INFO] org.codehaus.jackson:jackson-mapper-asl:jar:1.0.1:test
[INFO] org.eclipse.jdt:core:jar:3.1.1:test
[INFO] org.hamcrest:hamcrest-core:jar:1.1:test
[INFO] org.liquibase:liquibase-core:jar:2.0.3:test
[INFO] org.liquibase.ext:liquibase-slf4j:jar:0.0.1:test
[INFO] org.mortbay.jetty:jetty:jar:6.1.26:test
[INFO] org.mortbay.jetty:jetty-util:jar:6.1.26:test
[INFO] org.mortbay.jetty:jsp-2.1:jar:6.1.14:test
[INFO] org.mortbay.jetty:jsp-api-2.1:jar:6.1.14:test
[INFO] org.mortbay.jetty:servlet-api:jar:2.5-20081211:test
[INFO] org.mortbay.jetty:servlet-api-2.5:jar:6.1.14:test
[INFO] org.slf4j:jcl-over-slf4j:jar:1.6.4:compile
[INFO] org.slf4j:log4j-over-slf4j:jar:1.6.4:compile
[INFO] org.slf4j:slf4j-api:jar:1.6.4:compile
[INFO] org.springframework:spring-aop:jar:3.1.1.RELEASE:compile
[INFO] org.springframework:spring-asm:jar:3.1.1.RELEASE:compile
[INFO] org.springframework:spring-beans:jar:3.1.1.RELEASE:compile
[INFO] org.springframework:spring-context:jar:3.1.1.RELEASE:compile
[INFO] org.springframework:spring-context-support:jar:3.1.1.RELEASE:compile
[INFO] org.springframework:spring-core:jar:3.1.1.RELEASE:compile
[INFO] org.springframework:spring-expression:jar:3.1.1.RELEASE:compile
[INFO] org.springframework:spring-jdbc:jar:3.1.1.RELEASE:compile
[INFO] org.springframework:spring-test:jar:3.1.1.RELEASE:test
[INFO] org.springframework:spring-tx:jar:3.1.1.RELEASE:compile
[INFO] org.springframework.data:spring-data-hadoop:jar:1.0.0.BUILD-SNAPSHOT:c
ompile
[INFO] oro:oro:jar:2.0.8:test
[INFO] tomcat:jasper-compiler:jar:5.5.12:test
[INFO] tomcat:jasper-runtime:jar:5.5.12:test
[INFO] xmlenc:xmlenc:jar:0.52:test
What you desire, is no longer valid for Maven 3 (this used to be valid for Maven 2). Maven 3 will attempt to obtain the nearest dependency, effectively ensuring that only one of the compile or test scoped dependency is used for both the compile and test phases.
In your case org.apache.hadoop:hadoop-core:1.0.0:test overrides org.apache.hadoop:hadoop-core:0.20.2-cdh3u2:compile and hence becomes the nearest dependency. You may see the following warning displayed by Maven when running the mvn dependency:list goal, that alludes to this being a problem in your project model:
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be
unique: org.apache.hadoop:hadoop-core:jar -> version 0.20.2-cdh3u2 vs 1.0.0 # line xyz, column xyz
To 'fix' this, it would be better to split your tests into a separate project whose project model can define a separate set of test dependencies.
Looks like a maven bug - or if not, something that is fishy enough I wouldn't trust the documentation if there were any.
In your case, I would probably:
upgrade maven and see if the issue is fixed in the latest m3
try repackaging one of the hadoop versions with another artifact id or group name. maven-shade-plugin, don't bother changing the package name, but just introduce something maven won't know is no different from org.apache.hadoop:hadoop-core
try moving the tests to a separate project downstream
start debugging maven and understand what's going on exactly (and then fall back on 1 or 2...)

Resources