java - Sharing src/test classes between modules in a multi-module maven project -
I have a multi-module maven project. For this example, consider two modules:
< Ul> data consumer dependence on module user As the module is data . Module declares a group of core classes. It has been tested under src / test which they use. These tests require some long-rotating object creation, so I have a class with some utility methods to make these objects SampleDataHelper ) src / test hierarchy. I also have some tests in the Consumer I module which needs to be made of some of these long-rotating objects, I can use my consumer source / test I want to use my sampleddetahler class (defined in the data source / test ) in the tree-dwelling tests. Unfortunately, even if the data consumer , dependency of the consumer can not see the classes under the data source / test .
To counter it, I thought I could make the Other module ( data-test ), and SampleDataHelper Under src / main . After this I will include the data-test as the dependency of the test scope data . Unfortunately, it offers a circular dependency: data uses data-test , but also data-testing to Data is required .
The only solution I have is to put SampleDataHelper under the test package under data source / main and hopefully That no real app code can ever make calls.
How do I without src / main between my SampleDataHelper class module?
Your consumer project depends on your data project, so we are happy that the data was created before the consumer As a result, using the suggested techniques, I will make sure that your data project contains all the test codes that you want to configure to make POM a test jar to share:
& Lt; Plugin & gt; & Lt; Group & gt; Org.apache.maven.plugins & lt; / Group & gt; & Lt; ArtifactId & gt; Maven-Jar-plugin & lt; / ArtifactId> & Lt; Version & gt; 2.2 & lt; / Edition & gt; & Lt; Hanging & gt; & Lt; Execution & gt; & Lt; Goals & gt; & Lt; Goal & gt; Test-jar & lt; / Target & gt; & Lt; / Targets & gt; & Lt; / Execution & gt; & Lt; / Hanging & gt; & Lt; / Plugin & gt; Then your consumer project will depend on the general data JAR artifact, as well as additional test-jar artifacts, with the test scope of course:
& lt; Dependency & gt; & Lt; Group & gt; Com.foo & lt; / Group & gt; & Lt; ArtifactId & gt; Data & lt; / ArtifactId> & Lt; Version & gt; 1.0 & lt; / Edition & gt; & Lt; Type & gt; Test-jar & lt; / Type & gt; & Lt; Scope & gt; Trial & lt; / Scope & gt; & Lt; / Dependencies & gt; I have used this approach on many occasions and it works well.
Comments
Post a Comment