0

I have a multi-module project that has two modules A and B. Both have their own modules, here on refered as sub-modules.

I want to do some comparison between both types of modules. For example, I want to check that all sub-modules of A should have an associated sub-module in B. How can I do that?

I looked into maven-enforcer-plugin, but I only found examples of managing plugins and dependencies, not modules.

So far, I have been able to print out list of sub-modules of A using following command from this link:

mvn --also-make dependency:tree | grep maven-dependency-plugin | awk '{ print $(NF-1) }'

But when I try to output that to a file like this :

mvn dependency:list -DoutputFile="foo.txt"

I see that foo.txt is created in each and every sub-module of A, rather than module A(the aggregator). I need one single file with the list of dependencies, from which I can filter out the modules using

grep maven-dependency-plugin | awk '{ print $(NF-1) }'

So I need two things: 1. output the dependency:list or dependency:tree in one file for the aggregator, and 2. In the overall project, read both files from modules A and B and have a way to do some comparison and output results (fail the build if comparison gives undesired result).

Any pointers would be helpful.

EDIT:

Clarifying that I need all this to happen during build (mvn clean install) of the project, every time it builds.

Community
  • 1
  • 1
dc95
  • 1,319
  • 1
  • 22
  • 44

1 Answers1

0
  1. output the dependency:list or dependency:tree in one file for the aggregator

Just tweaking the command where you get the list of all the sub-modules for let's say A module, you can save the redirected list of all its submodule to a file as -

mvn --also-make dependency:tree | grep maven-dependency-plugin | awk '{ print $(NF-1) }' >> subModuleList.txt
  1. In the overall project, read both files from modules A and B and have a way to do some comparison and output results (fail the build if comparison gives a undesired result).

For the case of comparison assuming you have two text files in hand at this stage namely subModuleListA.txt and subModuleListB.txt. You can write a Test to parse these files and compare their elements. This test should fail for the undesired result and hence marking the complete build failure(also getting to log the reason for failure, I expect.)

Naman
  • 27,789
  • 26
  • 218
  • 353
  • How do I add mechanism to generate the txt file during the build? Because want this test to happen every time someone builds the project. – dc95 Mar 14 '17 at 08:39