I do need to build the modules it depends on first, but I don't want to run their tests. I've tried various invocations with -am -pl, this is the most recent, and based on maven :: run only single test in multi-module project
mvn test -DfailIfNoTests=false -Dtest="**" -am -pl service-api test
All of these tests should be in the com.myapp.service package, and packages below it. Ideally though, an answer won't rely on that.
Nothing I have tried works though? What's the magic invocation to compile process-resources for dependents, and run tests for just this module?
Related
i am trying to build maven command to run specific test:
i want to be able to execute this:
mvn test
mvn integration
mvn specificdata
so each test will go into a folder and run the suite
src/test
src/integration
src/specificdata
mvn test works with the test folder but when i run
mvn specificdata i get
[ERROR] Unknown life-cycle phase "specificdata".
same for integration
how can i make mvn run these tests independently?
This cannot be done in the way you describe it.
test is a phase and as such, part of the standard lifecycle. Calling mvn test does not only run tests, but executes the phases before test as well.
The standard lifecycle also offers phases for integration tests, esp. integration-test. Integration tests are usually put into src/test as well and distinguished by a naming convention. But beware: Calling mvn integration-test will call all previous phases (including test, compileetc.) as well.
https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
I have a project with the following subprojects:
foo-codegen
...which, as the name implies, performs code generation...
foo-maven-plugin
...which invokes foo-codegen during the build process.
Generally speaking, this works fine. The problem, though, is when I want to test foo-codegen: foo-maven-plugin isn't yet available during foo-codegen's build cycle if we're putting things together in dependency order, but the build process for the tests invokes that plugin to actually perform the necessary code generation.
What's the right way to break this chain? Should I move foo-codegen's tests into a third subproject? Use the Maven Invoker plugin rather than foo-maven-plugin for doing code generation during the test phase? Something else?
If you do a mvn install or mvn deploy to a repository on the plugin first, then you can run them any order and do a mvn compile separately.
I'm running the goal failsafe:integration-test on a multi-module project with the format:
Parent:
--------Module_A
--------Module_B
Consider a passing Test_B1_IT (in Module B) that tests something in Class_A1 (in Module A).
You now change Class_A1 and the test now fails. However, if you run the goal
mvn failsafe:integration-test
the test will still pass - changes aren't reflected until you run the deploy goal. I believe the goal is using the jar's from the repository, and not the most recent build from the current reactor.
If you run integration-test it works...but it seems to run all the unit tests as well (there doesn't seem to be a way to skip unit tests and run _IT integration tests).
I also see that it works for the goal integration-test or if I add "compile" before the failsafe goal. The first option, however, runs all tests (unit + integration)
Is this a problem with the failsafe plugin or just the way maven handles dependencies in multi-module projects? Should the best approach be to just add the compile option ?
The first thing is you can skip unit tests by simply given skip on command line like:
mvn -Dmaven.test.skip=true lifecycle
If you like to run integration test you shouldn't call the failsafe:integration-test goal, cause you are missing the pre-integration-test phase and the post-integration-test lifecylce phase.
A better approach is to use the reactor of Maven via calling
mvn -D... -am -pl Module_A lifecylcephase
The -am switch will make sure to compile all dependant modules.
Furthermore i would suggest to put the integration tests into a separate module which makes life easier like:
+-- root
+--- pom.xml
+--- mod1 (pom.xml)
+--- mod2 (pom.xml)
+--- mod-it (pom.xml)
The mod-it can be activated by using a profile like:
mvn -Prun-its ...
What you wrote about using the module is true. If you just call a goal the dependencies will be resolved against the local repository and of course not via the reactor, cause there is not reactor running in that case.
Nevertheless the integration test phase assumes that all unit tests have already been run so it makes sense to run the unit tests first like Maven does by its lifecycle. But you can influence that by using some properties to control that in detail. But usually running the unit tests shouldn't be a problem cause unit tests must run fast.
It seems that the assembly plugin (or jar/war plugin) are just dumb.
They just can't figure out whenever there is just nothing to do.
A basic "Makefile" won't recompile a target if all its dependencies are older than the target.
For maven, it seems that the packaging is done "all the time" !
if I do "mvn package" and then "mvn integration-test", Maven will process the packages again and again.
Since I build some fat-standalone jars : it takes a while !
Is it also the way is works for you, or is there something broken in my configuration.
Thanks in advance for your help,
Raphaël
In Maven exists a Life-Cycle which is run through every time you call a phase.
mvn integration-test
means to run all phases which are before integration-test (incl. integration-test itself) which includes in your case the package phase. Furthermore you shouldn't call integration-test cause the post-integration-test will not run in this case. You should call mvn verify instead.
The result from the above is you should simply call mvn integration-test and the package phase will run automatcially. Maven is not Make.
What exactly happens during this command:
mvn -pl ABC –am -amd?
Does it compile the code?
The reason I asked is I have purposely put an invalid file and when I run mvn -pl ABC -am -amd option I get successful result and I'm confused why Maven is not complaining about the errored file?
But if I use mvn install command it errors!
-pl or --projects allows you to select a specific set of projects to apply your goal, (e.g. clean install) this way saving the time you would spend waiting for a full build on a big project if you just need to build a couple modules.
You might wanna check the following section:
Specifying a Subset of Projects
-pl makes maven build only specified modules and not the whole project (in this case it's only ABC).
-am makes maven figure out what modules our target depends on and build them too(in this case it's ABC's dependencies).
If you say mvn -pl, and give no argument to -pl, you are asking maven to do absolutely nothing.
-pl assumes that you are sitting in a project with multiple modules, and want to build a subset. You just asked for the null subset.
You haven't actually given it a goal to run. mvn -pl Abc:Xyz -am -amd has two problems with it.
First of all, -amd implies -am, so you don't need both.
Secondly, you haven't given it a goal to run, like install, package, test, or compile.