Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Change target directory for a specific profile in the pom file

In the pom file, we can override project.build.directory for a specific profile

<profile>
  <id>foo</id>
  <build>
    <directory>${project.basedir}/foo_directory/target</directory>
  </build>
</profile>

My question is, what happens to other directories depending on project.build.directory?

for example these two:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<outputDirectory>${project.build.directory}/classes</outputDirectory>
<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>

If I run maven with foo profile and I use outputDirectory or testOutputDirectory will maven take into consideration the new target directory?

>Solution :

Yes, this should work.

You can verify this by running mvn help:effective-pom and mvn help:effective-pom -P foo to compare the effective-pom with the default profile and the foo profile.

You can then verify that the configuration property ${project.build.directory} is replaced by the correct value.

As a test i have configured the following in pom.xml:

    <profiles>
        <profile>
            <id>foo</id>
            <build>
                <directory>${project.basedir}/foo_directory/target</directory>
            </build>
        </profile>
    </profiles>

And the default effective pom becomes:

  <build>
    <sourceDirectory>D:\TestProject\src\main\java</sourceDirectory>
    <testSourceDirectory>D:\TestProject\src\test\java</testSourceDirectory>
    <outputDirectory>D:\TestProject\target\classes</outputDirectory>
    <testOutputDirectory>D:\TestProject\target\test-classes</testOutputDirectory>

And the foo effective pom becomes:

  <build>
    <sourceDirectory>D:\TestProject\src\main\java</sourceDirectory>
    <testSourceDirectory>D:\TestProject\src\test\java</testSourceDirectory>
    <outputDirectory>D:\TestProject\foo_directory\target\classes</outputDirectory>
    <testOutputDirectory>D:\TestProject\foo_directory\target\test-classes</testOutputDirectory>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading