Maven build plugin failed with official document

Refs to https://www.elastic.co/guide/en/elasticsearch/plugins/2.4/plugin-authors.html

I build my project with maven, and the pom.xml is the following:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.github.brickxu</groupId>
    <artifactId>audit</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.elasticsearch.plugin</groupId>
        <artifactId>plugins</artifactId>
        <version>2.4.6</version>
    </parent>

    <properties>
        <elasticsearch.version>2.4.6</elasticsearch.version>
        <elasticsearch.plugin.classname>com.github.birckxu.audit.AuditPlugin</elasticsearch.plugin.classname>
        <elasticsearch.plugin.name>elasticsearch-audit</elasticsearch.plugin.name>
        <elasticsearch.plugin.site>false</elasticsearch.plugin.site>
        <elasticsearch.plugin.jvm>true</elasticsearch.plugin.jvm>
        <elasticsearch.assembly.descriptor>src/main/assembly/assembly.xml</elasticsearch.assembly.descriptor>
        <skip.unit.tests>true</skip.unit.tests>
        <skip.integ.tests>true</skip.integ.tests>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

And I run mvn package with this pom.xml, it shows some error message:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building audit 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-versions) @ audit ---
[INFO] 
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-maven-version) @ audit ---
[INFO] 
[INFO] --- maven-enforcer-plugin:1.4.1:display-info (print-versions) @ audit ---
[INFO] Maven Version: 3.3.9
[INFO] JDK Version: 1.8.0_151 normalized as: 1.8.0-151
[INFO] OS Info: Arch: x86_64 Family: mac Name: mac os x Version: 10.12.6
[INFO] 
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-java-home-is-set) @ audit ---
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireEnvironmentVariable failed with message:
"JAVA_HOME must be set and point to the jdk to run the tests"
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.944 s
[INFO] Finished at: 2017-11-21T11:34:00+08:00
[INFO] Final Memory: 20M/309M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.4.1:enforce (enforce-java-home-is-set) on project audit: Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

but I already set $JAVA_HOME before.

➜  ~ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home
➜  ~ which java
/usr/bin/java
➜  ~ which javac
/usr/bin/javac

How to resolve this issue ? I found another same issue here but there is no answer.

Find the answer, Idea does not read the env variable correctly, use launchctl setenv JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home could fix it.

Please close this issue. Thanks

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.