javaspringspring-bootmavenveracode

How to compile in debug mode using maven without making changes to pom.xml?


I am trying to run some vulnerability scans(Veracode) on a spring boot application. However, the scan provider suggests running the scans with binaries compiled in debug mode using the following in pom.xml file.

<build>
  <plugins>
    <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration>
        <debug>true</debug>
        <debuglevel>lines,vars,source</debuglevel>
      </configuration>
    </plugin>
  </plugins>
</build>

However, we use the same pom.xml for production deployment where we don't want debug level jars.

Is there a way to create debug jars by passing some argument to the mvn command?


Solution

  • You can use profiles.

    <profiles>
      <profile>
        <id>debug</id>
        <build>
          <plugins>
            <plugin> 
              <artifactId>maven-compiler-plugin</artifactId> 
              <configuration>
                <debug>true</debug>
                <debuglevel>lines,vars,source</debuglevel>
              </configuration>
            </plugin>
          </plugins>
        </build>
      </profile>
    </profile>
    

    Profiles are activated in the mvn command, e.g., mvn ... -Pdebug.