Search code examples
mavenmaven-3pom.xml

What is workingDirectory in Maven POM.xml?


Want to understand what and why tag is used in Maven POM.xml. What is the significance of the tag?

Example:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <showDeprecation>true</showDeprecation>
                <compilerVersion>1.8</compilerVersion>
                <source>1.8</source>
                <target>1.8</target>
                <encoding>${project.build.sourceEncoding}</encoding>
                <workingDirectory>target/</workingDirectory>
            </configuration>
        </plugin>

Solution

  • There is no workingDirectory element in the Maven POM by default, see Maven POM reference for details about the element you can use in your POM.

    However, workingDirectory can exists in certain plugin configuration such as the exec:exec goal on the Maven Exec Plugin, for example:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.6.0</version>
        <executions>
          <execution>
            <goals>
              <goal>exec</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <executable>java</executable>
          <workingDirectory>target/</workingDirectory>
          <arguments>
            <argument>-classpath</argument>
            <classpath>
              <dependency>commons-io:commons-io</dependency>
              <dependency>commons-lang:commons-lang</dependency>
            </classpath>
            <argument>com.example.Main</argument>
          </arguments>
        </configuration>
      </plugin>
    

    Would execute java from the target directory. However, adding a workingDirectory in the Compiler plugin as in your example won't do anything - there is no such configuration.