How to print the actual MAVEN_OPTS that are being used?
Asked Answered
L

5

13

Is there a way to get maven to output the value of environment and maven variables during a build? This would be very useful for debugging things when they're going wrong.

Lab answered 2/7, 2010 at 16:11 Comment(1)
Note that the correct environment vairable name is $MAVEN_OPTS: maven.apache.org/configure.html#maven_opts-environment-variableAdenoidal
E
15

You can use Maven Help Plugin and help:system goal, so your pom will be:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>testMavenOpt</groupId>
    <artifactId>testMavenOpt</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>testMavenOpt</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-help-plugin</artifactId>
                <version>2.1</version>
            </plugin>
        </plugins>
    </build>
</project>

and you should execute mvn help:system

Enrique answered 19/7, 2010 at 12:49 Comment(2)
It lists all environment variables, so if you do not see the MAVEN_OPTIONS then they are not set in your environment. Or do you mean something else?Enrique
This works, but the name of the env var is MAVEN_OPTS not MAVEN_OPTIONS or MAVEN_OPT. If it's not there, then your build is using the defaults javac uses.Hocker
A
3

It'll require some changes to the pom.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.1</version>
  <executions>
    <execution>
      <phase>validate</phase>
      <goals>
        <goal>run</goal>
      </goals>
      <configuration>
        <tasks>
          <echo>[MAVEN_OPTIONS]${env.MAVEN_OPTIONS}</echo>
        </tasks>
      </configuration>
    </execution>
  </executions>
</plugin>

Of course, it might be simplest to run

echo $MAVEN_OPTS
Alphonsoalphonsus answered 2/7, 2010 at 16:20 Comment(1)
hi sblundy, I tried the way you suggested but I don't get anything printed (not even "[MAVEN_OPTIONS]". Here I pasted the entire output and the pom.xml ... I think the 'echo $MAVEN_OPT' might not tell what maven really sees, because often more then one place can be used to define those settings (i.e. .mavenrc) . I found handy to ask maven "what options do you actually see?" thnxLab
A
0

Run your maven with -X or --debug options

Command line example:

mvn clean compile --debug

You'll see environment information on your console.

Aeronaut answered 20/2, 2015 at 20:47 Comment(1)
This answer it´s not right, because the question is about MAVEN_OPTS environment variableAdeno
B
0

Add this plugin under plugins section in pom.xml and use mvn validate :

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.1</version>
  <executions>
    <execution>
      <phase>validate</phase>
      <goals>
        <goal>run</goal>
      </goals>
      <configuration>
        <tasks>
          <echo>Displaying value of system variables</echo>
          <echo> ${env.YOUR_ENVIRONMENT_VARIABLE_NAME}</echo>
        </tasks>
      </configuration>
    </execution>
  </executions>
</plugin>

This will print your env variable value.

Bipack answered 1/6, 2019 at 18:14 Comment(0)
B
0

Adding an option to the already provided answers.

There are different ways to pass JVM options to mvn as per https://maven.apache.org/configure.html you can do it using environment variable (MAVEN_OPTS) or file (${maven.projectBasedir}/.mvn/jvm.config).

I wanted to see which is picked up, and did so by starting a build then followed a ps listing to assert what was picked up, eg

ps -ef | grep SomeOption
Babbie answered 21/9, 2020 at 14:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.