Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8700423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:09:55+00:00 2026-06-13T02:09:55+00:00

In a Maven Multi Module Project structured like this: P // parent project *

  • 0

In a Maven Multi Module Project structured like this:

P // parent project
  * A // first module
  * B // second module, containing the test in question

the pom.xml of A contains this:

 <profile>
   <id>theProfile</id>
     <build>
       <resources>
         <resource>
           <directory>src/main/ctx/someDir</directory>
             <filtering>true</filtering>
         </resource>
         <resource>
         <resource>
           <directory>src/main/resources</directory>
         </resource>
       </resources>
     <build>
   </profile>         

When the complete project P is run and this profile is activated is the availability of src/test/resources as part of the classpath during tests of B affected in any way?

If yes, in which way, and how to change the definition so the given resources are

a) purely additional

b) affect only A in which they are defined.

If No, is the src/main/resources part superfluous?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:09:56+00:00Added an answer on June 13, 2026 at 2:09 am

    TL;DR A) No; B) No; if your <resources> was <resources combine.children="append"> then you could omit it, but as written, No

    Long answer

    If you run the build from the root, and assuming that B depends on A

    The classpath you get depends on the phase that you progress the whole reactor to.

    Where the phase is before the package phase of the lifecycle, the classpath will reference the ${project.build.outputDirectory} directory for dependencies within the reactor

    Where the phase is on or after the package phase of the lifecycle, the classpath will reference the constructed JAR file, e.g. ${project.build.directory}/${project.build.finalName}.jar

    So to give you some concrete examples:

    $ mvn compile
    

    That will do nothing in P because P is a <packaging>pom</packaging> and by default that packaging does not bind any [classpath relevant] plugins to lifecycle phases prior to install.

    When we hit A it will list up all of A’s dependencies in the compile classpath, since none of these come from the reactor, they will be resolved from the local cache (i.e. ~/.m2/repository) so if A uses log4j, you will have a compile classpath like

    ${JAVA_HOME}/lib/rt.jar:~/.m2/repository/log4j/log4j/1.2.16/log4j-1.2.16.jar
    

    We have not specified a phase after compile, so no plugins requiring the test classpath will be invoked, so not relevant at this point in time.

    Now we move to B. B’s dependencies include A, so it will reference the main artifact for A which (as jar:jar hasn’t run will be pointing to A’s ${project.build.outputDirectory}) B’s compile classpath will look a little something like this

    ${JAVA_HOME}/lib/rt.jar:~/.m2/repository/log4j/log4j/1.2.16/log4j-1.2.16.jar
    :./A/target/classes
    

    [Note: as we invoked from the P directory the current directory is the P’s ${basedir} so B’s value of ${basedir} will be ./B]

    Though B’s own dependencies may alter the classpath depending on the order of dependencies in its pom and whether it applies exclusions or version overrides on the transitive dependencies

    OK. That was simple enough to get us started… next we move up the lifecycle to the test phase

    $ mvn test
    

    P has the same story as before

    A has the same compile story as before. When we hit the test-compile phase the tests will be compiled with the following classpath (assuming using junit for tests)

    ${JAVA_HOME}/lib/rt.jar:~/.m2/repository/log4j/log4j/1.2.16/log4j-1.2.16.jar
    :./A/target/classes:~/.m2/repository/junit/junit/4.10/junit-4.10.jar
    

    [I may have the ordering of elements slightly wrong as I’d need to dig into mvn -X to confirm, but the principal is correct]

    When we get to the test phase, surefire:test will build up the test classpath. By default it puts test dependencies ahead of non-test dependencies but it is configurable. So A’s test classes will execute with a classpath somewhat like this

    ${JAVA_HOME}/lib/rt.jar:./A/target/test-classes:~/.m2/repository/junit/junit/4.10/junit-4.10.jar
    :~/.m2/repository/log4j/log4j/1.2.16/log4j-1.2.16.jar:./A/target/classes
    

    This allows for things like using matching resources in the test classpath to override the production defaults in order to make the code testable, etc.

    B’s compile classpath is the same as before. I am also throwing in that B depend on a different version of JUnit. The test-compile classpath shouldn’t be a surprise

    ${JAVA_HOME}/lib/rt.jar:~/.m2/repository/log4j/log4j/1.2.16/log4j-1.2.16.jar
    :./A/target/classes:./B/target/classes
    :~/.m2/repository/junit/junit/4.11/junit-4.11.jar
    

    Now things get interesting, B’s classpath as constructed by surefire (again the ordering of test scoped dependencies can be modified, so assuming you are using the default). A’s test classpath is not transitive so will not be exposed to B.

    ${JAVA_HOME}/lib/rt.jar:./B/target/test-classes
    :~/.m2/repository/junit/junit/4.11/junit-4.11.jar
    :~/.m2/repository/log4j/log4j/1.2.16/log4j-1.2.16.jar
    :./A/target/classes:./B/target/classes
    

    Finally, let’s go as far as the package phase and see how that effects the classpath.

    $ mvn package
    

    P is the same as before.

    A is actually the same as before, because none of its dependencies come from within the reactor. But the key thing here is that when jar:jar runs in the package phase it replaces the exposed classpath… this will effect how B sees A.

    B’s classpaths are constructed the same as before, except that now B sees A’s .jar and not A’s compiled classes. So B’s compile classpath will be

    ${JAVA_HOME}/lib/rt.jar:~/.m2/repository/log4j/log4j/1.2.16/log4j-1.2.16.jar
    :./A/target/A-1.0-SNAPSHOT.jar
    

    B’s test-compile classpath will look something like this

    ${JAVA_HOME}/lib/rt.jar:~/.m2/repository/log4j/log4j/1.2.16/log4j-1.2.16.jar
    :./A/target/A-1.0-SNAPSHOT.jar:./B/target/classes
    :~/.m2/repository/junit/junit/4.11/junit-4.11.jar
    

    B’s test classpath will look something like this:

    ${JAVA_HOME}/lib/rt.jar:./B/target/test-classes
    :~/.m2/repository/junit/junit/4.11/junit-4.11.jar
    :~/.m2/repository/log4j/log4j/1.2.16/log4j-1.2.16.jar
    :./A/target/A-1.0-SNAPSHOT.jar:./B/target/classes
    

    Now just to give you the final picture

    $ mvn install -DskipTests
    $ mvn test -f B/pom.xmml
    

    In the second invokation of Maven where we are just running with a single module recactor (i.e. B is the only module in the reactor), now A will be resolved from the local cache, so we get the test classpath something like

    ${JAVA_HOME}/lib/rt.jar:./B/target/test-classes
    :~/.m2/repository/junit/junit/4.11/junit-4.11.jar
    :~/.m2/repository/log4j/log4j/1.2.16/log4j-1.2.16.jar
    :~/.m2/repository/com/mydomain/myproject/A/1.0-SNAPSHOT/A-1.0-SNAPSHOT.jar
    :./B/target/classes
    

    Now hopefully that has somewhat clarified the mystery of the classpaths from Maven.

    How do your profiles mix into this… well they do nothing to your classpath. What they do instead is copy files into ${project.build.outputDirectory.

    When A reaches the process-resources phase it will copy all the defined resources into ${project.build.outputDirectoy} so

    $ mvn package -PtheProfile
    

    Will construct the exact same classpaths but the files in ./A/src/main/ctx/someDir will be copied with filtering into A’s ${project.build.outputDirectoy} while retaining their directory structure and the files in ./A/src/main/resources will be copied in to A’s ${project.build.outputDirectoy} without filtering while retaining their directory structure. Then when we hit the package phase jar:jar will just slurp up all those files into the .jar again.

    I hope this answer helps you understand what is going on better… I also hope you are starting to see why using profiles to affect the built artifacts can result in headaches, e.g.

    $ mvn clean install -PtheProfile -DskipTests
    $ mvn test -f B/pom.xml
    

    will have different results from

    $ mvn clean install -DskipTests
    $ mvn test -f B/pom.xml
    

    as the local repository cache does not know what profiles were active when the artifact was installed into the local repository so the first case builds a different A.jar from the second case…

    But that is more of a hint at future issues you may encounter and why we advocate sticking to the Maven way and avoiding the use of profiles to modify either the transitively exposed classpath or the built artifact. The use of profiles to modify the test classpath though is quite useful (for example when the tests run on JDK1.5 vs JDK1.6 vs JDK1.7 you may need to modify the classpath for the tests… this is OK as the test classpath is non-transitive)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a multi-module Maven project that uses Spring IoC, something like parent-proj -
I have Maven multi-module project with such structure: parent-pom-project -- module1 -- module2 At
I have a multi-module maven project like this: -project +-sub-project1 +-sub-project2 For my JUnit
I have a Maven multi-module project and I need two different parent POMs in
I'm creating additional module to already multi-module maven project. And for this one I
I have a multi module maven project and I would like to use versions
I have a big multi-module Maven project with thousands of tests. Each test loads
I have a multi-module Maven project, and I would like to assemble together artifacts
I want to create maven multi module project, but it should not like normal
Context big project with multi maven module or single maven module structure Question did

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.