Home > Mobile >  Change target directory for a specific profile in the pom file
Change target directory for a specific profile in the pom file

Time:05-26

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:

<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?

CodePudding user response:

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>
  • Related