 | In a multi modules project where you have write API or common code for unit tests in one project and want to reuse these in the tests for another project. Maven will crash during the compile phase if you do not make the following. | Maven rules of the game: - The main code in src/main/java is visible across modules if you did specify project
dependencies in pom.xml. - Test code reside in src/test/java and is not shared across modules, moreover
- Test code can use any code from src/main/java but not the other way around, which
make sense as we want to clearly separate test code (junit testcases) from code shipped. The solution is to create additional test jar for each module, this is done by putting in the parent pom (lets call it parent-pom.xml) inside the <build></build> tags the following: 1: <plugin>
2: <groupId>org.apache.maven.plugins</groupId>
3: <artifactId>maven-jar-plugin</artifactId>
4: <executions>
5: <execution>
6: <goals>
7: <goal>test-jar</goal>
8: </goals>
9: </execution>
10: </executions>
11: </plugin>
This will create for each modules an additional jar named {artifactId}-{version}-tests.jar
during the goal test-jar
Now for every modules where you want to reuse test classes, all you have to do in to put in every
modules pom.xml a dependency to that test jar by adding the tests classifier
1: <dependency>
2: <groupId>yourGroup</groupId>
3: <artifactId>yourReusableModuleArtifact</artifactId>
4: <version>0.1-SNAPSHOT</version>
5: <classifier>tests</classifier>
6: <scope>test</scope>
7: </dependency>
This has work for me with Maven 2.0.8
Related Posts
-
I forgot to blog about this presentation at JAZOON 2008, but I did never forget the added value of this plugin. It is not currently in Apache Maven core but will for sure find its way as an official plugin one day, since it solve elegantly a common problem: technology management Maven does not know the concept of an artifact life cycle. Su 7 days ago
-
It is not unusual in a project to have a huge number of third party artifacts and Plug-in. Apache Maven help you keep track of them, along with their transitive dependencies.
But how do you know when a new version of an artifact is available? This is where the Maven Versions plug-in come hand in.
The Versions Plug-in is used when you wa 7 days ago
-
In which order are Apache Maven profiles executed? are Apache Maven profiles ordered? how can you insured that Apache Maven profiles are activated in the right order? You normally don’t end up with these questions, issues may only appear if Some profiles are dependent each other, Some profiles can not run in any order, The use case 28 days ago
-
I won’t explain you how to write any JBehave tests as the online documentation is more than complete. I prefer to show you how to make them run in eclipse, and in Apache Maven as the example were not easy to run (scenario are wrongly in src/main/java). JBehave is a framework for Behaviour-Driven Development Behaviour-driven dev 42 days ago
-
I found this time a new way to deploy Maven artefacts using the Oracle Weblogic Ant API!
If you remember my previous post, there is many ways to deploy your war/ear to Oracle Weblogic
Using Oracle Weblogic development mode, a mode in which a simple copy of your files in a specific autodeploy directory trigger the update/install o 62 days ago
-
I was getting mad because jetty was refusing to redeploy my static files (xhtml, css) in Eclipse until I find the reason The Jetty Web Server provides a HTTP server and Servlet container capable of serving static and dynamic contend either from a standalone or embedded instantiations. Jetty buffers static content for webapps such as html files, 96 days ago
-
I was fighting today against the maven-release-plugin of maven, solving complicated errors in a row. As I am convince I made all possible errors, I think it is worse to compile my findings here to help others :-)
Maven Release Plugin
This plugin is used to release a project with Maven, saving a lot of repetitive, manual work. 159 days ago
-
Subversion (SVN) is an open source version control system. It allows users to keep track of changes made over time to any type of electronic data. Typical uses are versioning source code, web pages or design documents. Installing the latest Subversion (svn) version 1.6.6 is a bit more difficult than just running apt-get install subversion, as t 159 days ago
-
In this small post I will show you how to deploy automatically some artifacts of your build into Weblogic 10.3 by using the weblogic-maven-plugin
This plugin will support various tasks within the Weblogic 8.1 and 9.x environment. Such tasks as deploy, undeploy,clientgen,servicegen, and appc are supported as well as many others. The 159 days ago
-
If your Artifactory installation grows of many Gb each day - althought you do not deploy so many new artifacts. I suggest you to look under the repositories settings.
All your local repositories are configured as default with Snapshot Version Behavior = Non-Unique. As stated in the manual, all deployed SNAPSHOTS with be keep with unique time-sta 168 days ago
relatedArticles
|