{"record":{"id":"d92a2a706721c121","repo":"apache/maven","slug":"d-s-system-property-is-not-set","errorCode":null,"errorMessage":"-D%s system property is not set.","messagePattern":"-D(.+?) system property is not set\\.","errorType":"console","errorClass":"ExitException","httpStatus":null,"severity":"error","filePath":"compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java","lineNumber":345,"sourceCode":"\n            return 1;\n        } finally {\n            if (localContainer != null) {\n                localContainer.dispose();\n            }\n        }\n    }\n\n    void initialize(CliRequest cliRequest) throws ExitException {\n        if (cliRequest.workingDirectory == null) {\n            cliRequest.workingDirectory = System.getProperty(\"user.dir\");\n        }\n\n        if (cliRequest.multiModuleProjectDirectory == null) {\n            String basedirProperty = System.getProperty(MULTIMODULE_PROJECT_DIRECTORY);\n            if (basedirProperty == null) {\n                System.err.format(\"-D%s system property is not set.\", MULTIMODULE_PROJECT_DIRECTORY);\n                throw new ExitException(1);\n            }\n            File basedir = new File(basedirProperty);\n            try {\n                cliRequest.multiModuleProjectDirectory = basedir.getCanonicalFile();\n            } catch (IOException e) {\n                cliRequest.multiModuleProjectDirectory = basedir.getAbsoluteFile();\n            }\n        }\n\n        // We need to locate the top level project which may be pointed at using\n        // the -f/--file option.  However, the command line isn't parsed yet, so\n        // we need to iterate through the args to find it and act upon it.\n        Path topDirectory = fileSystem.getPath(cliRequest.workingDirectory);\n        boolean isAltFile = false;\n        for (String arg : cliRequest.args) {\n            if (isAltFile) {\n                // this is the argument following -f/--file\n                Path path = topDirectory.resolve(stripLeadingAndTrailingQuotes(arg));","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java#L327-L363","documentation":"MavenCli.initialize() requires the system property maven.multiModuleProjectDirectory to be set: it locates the root of the multi-module project (the directory containing .mvn). The official mvn/mvnw launcher scripts export it before starting the JVM; if the JVM is started without it (for example by invoking org.apache.maven.cli.MavenCli.main directly or through a custom launcher), the message '-Dmaven.multiModuleProjectDirectory system property is not set.' is printed to stderr and ExitException aborts startup with code 1.","triggerScenarios":"Running java -classpath ... org.apache.maven.cli.MavenCli (or MavenCli.doMain in embedded tooling) without -Dmaven.multiModuleProjectDirectory=<dir>; using a third-party launcher or IDE run configuration that starts the Maven JVM itself and does not set the property.","commonSituations":"Developers starting MavenCli from an IDE 'main class' run configuration instead of the mvn script; custom Gradle/CI wrappers invoking the embedded Maven CLI; older or stripped-down launch scripts from Maven distributions predating 3.3.1 (when the property was introduced).","solutions":["Invoke Maven through the standard mvn or mvnw scripts, which set the property automatically","If you must start the JVM yourself, add -Dmaven.multiModuleProjectDirectory=$PWD (pointing at the project root containing .mvn, or the cwd)","In IDE run configurations, launch via the IDE's Maven integration or MavenExec/IdeMain-style helpers rather than a bare main() call","Ensure the launcher you use ships from the same Maven version as the embedded classes (mixing an old script with new embedder classes causes this)"],"exampleFix":"# before\njava -classpath maven-embedder.jar:... org.apache.maven.cli.MavenCli compile\n# -> -Dmaven.multiModuleProjectDirectory system property is not set.\n\n# after\njava -Dmaven.multiModuleProjectDirectory=\"$PWD\" \\\n     -classpath maven-embedder.jar:... org.apache.maven.cli.MavenCli compile","handlingStrategy":"validation","validationCode":"import org.apache.maven.cli.MavenCli;\n\n// before embedding/invoking MavenCli main\nString basedir = System.getProperty(MavenCli.MULTIMODULE_PROJECT_DIRECTORY);\nif (basedir == null) {\n    System.setProperty(MavenCli.MULTIMODULE_PROJECT_DIRECTORY, System.getProperty(\"user.dir\"));\n}\n// now safe to invoke MavenCli.main(args)","typeGuard":null,"tryCatchPattern":"try {\n    cli.doMain(args, workingDir, stdout, stderr);\n} catch (ExitException e) {\n    if (stderrCapture.contains(\"multiModuleProjectDirectory\")) {\n        retryWithSystemProperty(\"-Dmaven.multiModuleProjectDirectory=\" + workingDir); // fix and rerun once\n    } else {\n        process.exit(e.getExitCode());\n    }\n}","preventionTips":["Always launch Maven through mvn / mvnw scripts or the IDE's Maven runner — they set the property for you","In embedded tooling, set the system property programmatically before calling MavenCli, sourced from the detected project root","Pin launcher scripts and embedder to the same Maven version to avoid property-contract mismatches"],"tags":["maven","cli","embedder","system-property","startup"],"backgroundTag":"missing-system-property","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}