How can i run maven tests against a previous deployed artifact of the same artifact? - testing

I have an artifact abc which has some tests. I have different versions of abc within my repository. I now want to be able to run the latest tests against the 'old build' of the project.
I tried to add the artifact itself to the test dependencies but this (of course) results in a cyclic reference error of the maven reactor when building the tests via:
mvn compiler:testCompile
mvn surefire:test
Is there any smart way to run tests against a previous old build/artifact?
Must i create a new pom.xml in which i define the solo test execution?
Or should i add a postfix to my current artifact when executing the tests? (This would avoid a cyclic reference error)

Separate the tests out into a separate module/project that depends on the classes it tests. Then create separate profiles where you change the dependency to be on older releases.

The problem I foresee with what you're trying to do is that the package phase comes after the test phase of the maven lifecycle. Which to me implies that maven runs unit tests against the compiled classes and not the physical jar file (generated in the package phase). You'll therefore have to replace the contents of the projects /target/classes folder with the classes in the "older" jar.

Related

Selenium Java and Maven generate test jars without running the tests

I'm using Azure DevOps for CI/CD and for CI portion, I want to package the entire project and the CD portion will execute the tests from the jars
I can't seem to generate the executables though. I am using PageObject model so my layout for my maven project is as such
---src/main/java
-------PageObject
---src/test/java
------>tests here
My goal in Azure DevOps is to make sure the code compiles and package up the tests and drop them into an artifact. The release will then run the tests from this artifact. I don't want to drop the entire repo into the artifact, rather just the binaries (so whatever is in the ~/target/ folder.
It seems that when I try to compile, there are not any jars that are created.
I do not want the CI portion to execute the tests; simiply package up the artifact is my goal here.

Dependency library after ant task in Maven2

I have a system dependency on a local jar which is compiled by a maven ant execution task using maven-ant-run plugin. How can I make sure that the ant task is executed before executing the dependency task. I am using system scope for a relative path where the jar is present after compilation.
It doesn't depend upon the scope of dependency, it depends that with which life-cycle phase you have bind the execution of the goal for any specific plug-in.
One possibility is to create a multi-module project with two modules. Module 1 should compile and place that dependency before building Module 2 (which will be having your existing project)

Building Products with Maven

I'm fairly new to Maven and I'd like to use it to build a multi-module project.
Lets assume I have the following svn repository structure:
- /trunk/common-services/login-service
(.jar) [re-usable components]
- /trunk/services/mybusiness-service
(.jar)
- /trunk/webservices/mybusiness-rest
(.war)
- /trunk/products/myproduct
(pom) [issue mvn command here]
What I'd like to be able to do is to checkout and build the entire "product" from a single pom using a single mvn command (from a developers pov as well as a CI pov). It's safe to assume that I have the trunk checked out.
How do I do this using Maven? I've looked at the Maven reactor plugin, but I can't figure out how to use it correctly (if it is the correct plugin to use).
The reactor plugin assumes each module has its pom.xml.
For your use case, you would want to create a pom.xml for each module (login-service, mybusiness-service and mybusiness-rest). You would specify the dependencies in each of the modules. For instance, if your mybusiness-rest depends on login-service and mybusiness-service, you would specify these projects as dependencies.
You would have a pom.xml in /trunk which specifies each of the modules to be built. You can use the reactor features in this pom.xml to determine, when to build (or not build) specific modules.
Your developers and CI can build using this single pom.

Configure a hudson maven job to keep building if there are test failures, but only deploy if there are no test failures

I've created a hudson job for our maven multi-project with 5 modules to deploy the SNAPSHOT artifacts to the maven repository. That's ok, as long as it builds successfully without test failures. However, now I'd like to fulfill the following requirements:
When a module has a test failure, the build should continue bulding and test the other modules, but turn yellow. Using -Dmaven.test.failure.ignore=true accomplishes, but fails at the next requirement.
When a module has a test failure, none of the artifacts should be deployed to the maven repository. Other projects depend on the snapshots this project and those projects only want to use the latest snapshots that don't have any failing tests.
Preferably, use the hudson maven integration instead of a free script we get the hudson report pages (red/yellow/blue status per module, build log error coloring, ...). Specifically running the maven build twice (first mvn test -Dmaven.test.failure.ignore=true, than mvn deploy -DskipTests) is not a solution because it's a performance loss and it confuses the hudson report pages and it's not atomic (it updates from the repositories again in the second build).
Is there any way to accomplish this?
There is an post build option called Deploy artifacts to Maven repository. If you do not select Deploy even if the build is unstable, then that mean if test fails, it won't deploy anything. Together with the -fae in the command, thing should work in your desired way
maybe you can try use mvn -fae option with you jobs on hudson - it make maven fail only after full build
If build time isn't a problem for you, I think the better option is to create another job, just for deploying. Something like this:
Configure your original job (let's call it "build job") with "mvn -fae clean install"
Create a new job ("deploy job") with "mvn deploy", and don't configure any Build triggers for it
In the "build job", enable the Build other projects option, under Post-build actions and set it to run your "deploy job".
Maybe you can try to configure both jobs to use the same workspace, saving some time on the whole build/deploy process.
If you happen to use Artifactory as a repository manager, you can use the Hudson/Jenkins Artifactory plugin to deploy your artifacts. This plugin will only deploy your artifacts if all tests pass for all modules of a Maven build.

Maven adds class files of snapshot dependencies

on my Windows machine I do have several proeject that I build with maven. At the moment they are all in SNAPSHOT-State. When I build a project that relies on one of the other projects maven always adds the class files of the other projects to the jar.
If I build the project on my CI-Server this problem does not occur. Does anyone have an idea why maven adds the class files to my jar?
I'm using maven 2.2.1
When I build a project that relies on one of the other projects maven always adds the class files of the other projects to the jar.
This is not a default behavior and, if it happens, you're somehow telling Maven to do so. If you want to hunt potential discrepancies, check the effective-pom, the effective-settings, the active-profiles using the following goals on both machines:
help:effective-pom
help:effective-settings
help:active-profiles
Also double check how Maven is invoked on the CI machine (extra command line parameter, etc).