Maven Transitive dependencies of dependencies in test scope included into a package - testing

I don't understand why transitive dependencies of test scope dependencies are included into package (from maven package phase). I'm using maven-war-plugin with default settings.
It doesn't make sense, does it ? The problems arise when you have 10 test scope deps, all with some logging transitive dependencies, and you have to exclude all of them. Not only that one has to do it in compile scope dependencies, but even for test scope deps.

Maven bug MNG-5150 breaks at least jboss-packaging-plugin as described in MJBOSSPACK-40.
I would guess that the same bug also breaks maven-war-plugin.

Related

In Ivy, how to choose the latest version of transitive dependencies?

Is there a way to tell Ivy to prefer the latest version of a particular library among the transitive dependencies, without turning the transitive dependency into a direct dependency?
After retrieving the artifacts required for a build I end up with two versions of the same library, both as transitive dependencies. I've run a report so I know where the libraries are coming from but I'd prefer not to end up with references to transitive libraries in my ivy.xml file.
The Ivy manual states "If no specific conflict manager is defined, a default conflict manager is used for all modules. The current default conflict manager is the 'latest-revision' conflict manager". Apparently that doesn't apply to transitive dependencies.
Is there a way achieve what I want without directly referencing transitive libraries?
Transitive dependencies are dependencies of your dependencies, so conflicts can occur when one or more versions of the same library are referenced. This is where the conflict manager functionality kicks in. By default, ivy will choose the most recent version, working on the assumption that most libraries are backwardly compatible. If you review the report generated by the report task you'll see the other version(s) marked as "evicted".
Your question appears to put forward an alternative mode of operation? Perhaps an example would help.

How to avoid maven compiling testClass in normale compiling

I have a default maven project:
/src/main/java
/src/test/java (include *Test.java).
When I exeucte "mvn compile", maven also tries to compile the testClasses under /src/test/java. This fails, as of some dependencies such as JUnit are under "test"-scope. Changing the scope of e.g. JUnit to "provided" everything works fine.
How can I avoid maven to compile testClasses when compiling? In my understanding, I expect to maven to compile this files only when executing "testcompile".
I am using maven 2.2.1
I believe it is nothing to do with the scope of JUnit. Normally we set JUnit's scope to test (instead of provided) and everything is just fine.
src/test/java is compiled by Maven Compiler Plugin's testCompile goal. However, you don't need to explicitly run that goal. Please have a look in topics about Maven's Lifecycle. For example, if you run maven install, it is implicitly going through many phases (e.g. compile, compile test, generate resources etc), and many of them is bounded to a default plugin goal.
If you want to avoid test source from building, from Maven Compiler Plugin's usage page, compiler:testCompile will be skipped if you turn off testing by setting maven.test.skip=true
So, if your unit tests are not yet ready, just build with Maven, with -Dmaven.test.skip=true parameter.
Just to add, this is absolutely not a good practice to assume "unit test failing" being normal during development.
Just use the skip parameter for the maven-surefire-plugin which skip tests as well as compiling the test.
The pom.xml had defined "sourceDirectory" incorrectly. Removing it fixed the issue
Instead of command "maven clean compile" , use "mvn -B -Dmaven.test.skip=true clean compile". This parameter skips test.

Maven errors when building the project for transitive dependencies

The POM for org.apache.cxf:cxf:jar:2.4.2 is invalid, transitive dependencies (if any) will not be available
It seems like the .pm file that captures the dependency information got corrupted (either when dowloading or is already corrupted in the central repository). Try a different version

how to run only parent pom.xml in maven multi-module project

I have maven multi-modules project. At the parent level, i have some java files. And in the parent pom.xml, at the package phase i do some stuff.
Usually, when i run mvn package at parent level, the package phase of parent pom will be run and all the modules will be packaged as well.
I am looking for a way that allow me to do these (when i run mvn package):
allow me to run only paren pom.xml (the script at the package phase), not the modules. This is the 1st priority.
allow me to run paren pom.xml and some particular modules (like module 1, module 2 BUT not module 3 , module 4).
Can i use profile for those issue?
Thanks.
While I agree with the fact that you may not have optimal project structure, the answer is that Maven 2.2.1 has an option "--non-recursive" which satisfies your first requirement:
-N,--non-recursive Do not recurse into sub-projects
So something like this:
mvn --non-recursive clean compile
Why do you want to have java code on the top level? In my opinion this is not a very good idea. Have your code in the subprojects and let the top-level project be responsible for holding the general information and configuration of the entire project.
If you have some base-library code in the top-level project now, you can put it in a sub-project and set up dependencies between the projects.
Take a look at Maven parent pom vs modules pom
The nature of your question indicates that your project structure may not be optimal.

maven dependencies in profiles during release build

I have a maven module which has several dependencies that are contained in profiles. When preparing a release build using the release plugin (i.e. mvn release:prepare), the versions of those dependencies do not get replaced, instead they remain the SNAPSHOT dependencies, even though the profiles are active (we run mvn release:prepare -Psomeprofile). I have also tried adding -Darguments="-Psomeprofile" to the mvn call, but this did not help either.
How can I make the release plugin also replace the versions of dependencies that are contained in profiles?
This looks like MRELEASE-354, "Versions defined in profiles are not updated". The workaround if to use
<version>${project.version}</version>
for the dependencies defined inside profiles.