System property maven.home is set but 'java.lang.IllegalStateException: We could not find the maven executable mvn somewhere' is thrown (original) (raw)

Describe the bug
System property maven.home is set in Intellji but the class MavenITExtension is thrown

java.lang.IllegalStateException: We could not find the maven executable `mvn` somewhere
    at com.soebes.itf.jupiter.extension.MavenITExtension.beforeTestExecution(MavenITExtension.java:171)

To Reproduce

I write following test that fails

class MavenLocatorTest {

    @Test
    void findMvn() {
        Properties properties = new Properties();
        properties.setProperty("maven.home", "/home/sparsick/.sdkman/candidates/maven/3.6.3");
        System.setProperties(properties);

        MavenLocator mavenLocatorUnderTest = new MavenLocator();
        Optional<File> mvnLocation = mavenLocatorUnderTest.findMvn();

        assertThat(mvnLocation).isPresent();
    }
}

I debugged MavenLocatorand mvn executable is found but then the method checkExecutableViaPathEnvironment is searching mvn in the PATH variable. During the debug session the PATH variable is /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games and therefor Optional.empty() is returned. On my CLI echo $PATH returns
a different value.

Current behavior
An exception is thrown

Expected behavior
mvn is found and the test start to run indepent if mvn is set in $PATH

The used versions
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /home/sparsick/.sdkman/candidates/maven/current
Java version: 11.0.6, vendor: Eclipse OpenJ9, runtime: /home/sparsick/.sdkman/candidates/java/11.0.6.j9-adpt
Default locale: de_DE, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-99-generic", arch: "amd64", family: "unix"

Intellji 2020.1