{"record":{"id":"23ed261ff6c83c24","repo":"OpenAPITools/openapi-generator","slug":"either-addcompilesourceroot-or-addtestcompileso","errorCode":null,"errorMessage":"Either 'addCompileSourceRoot' or 'addTestCompileSourceRoot' may be active, not both.","messagePattern":"Either 'addCompileSourceRoot' or 'addTestCompileSourceRoot' may be active, not both\\.","errorType":"exception","errorClass":"MojoExecutionException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java","lineNumber":1225,"sourceCode":"            name = Files.getNameWithoutExtension(segments[segments.length - 1]);\n        }\n\n        return new File(output.getPath() + File.separatorChar + \".openapi-generator\" + File.separatorChar + name + \"-\" + mojo.getExecutionId() + \".sha256\");\n    }\n\n    private String getCompileSourceRoot() {\n        final Object sourceFolderObject =\n                configOptions == null ? null : configOptions\n                        .get(CodegenConstants.SOURCE_FOLDER);\n        final String sourceFolder = sourceFolderObject != null ? sourceFolderObject.toString() : \"src/main/java\";\n\n        return output.getPath() + File.separatorChar + sourceFolder;\n    }\n\n    private void addCompileSourceRootIfConfigured() throws MojoExecutionException {\n        if (addCompileSourceRoot) {\n            if (addTestCompileSourceRoot) {\n                throw new MojoExecutionException(\"Either 'addCompileSourceRoot' or 'addTestCompileSourceRoot' may be active, not both.\");\n            }\n            project.addCompileSourceRoot(getCompileSourceRoot());\n        } else if (addTestCompileSourceRoot) {\n            project.addTestCompileSourceRoot(getCompileSourceRoot());\n        }\n    }\n\n    /**\n     * This method enables conversion of true/false strings in\n     * config.additionalProperties (configuration/configOptions) to proper booleans.\n     * This enables mustache files to handle the properties better.\n     *\n     * @param config\n     */\n    private void adjustAdditionalProperties(final CodegenConfig config) {\n        Map<String, Object> configAdditionalProperties = config.additionalProperties();\n        Set<String> keySet = configAdditionalProperties.keySet();\n        for (String key : keySet) {","sourceCodeStart":1207,"sourceCodeEnd":1243,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java#L1207-L1243","documentation":"Thrown by addCompileSourceRootIfConfigured() in CodeGenMojo when both <addCompileSourceRoot> and <addTestCompileSourceRoot> are true. The plugin would otherwise add the same generated-sources root to both the main and test compile roots, causing duplicate classes, so it rejects the combination up front with a MojoExecutionException.","triggerScenarios":"Generate goal configuration containing <addCompileSourceRoot>true</addCompileSourceRoot> and <addTestCompileSourceRoot>true</addTestCompileSourceRoot> simultaneously — commonly after copy-pasting test-generation config into main-generation config, or flipping a single boolean into two booleans during a refactor.","commonSituations":"One execution generating models for main code and another for tests, where someone enabled both flags in the shared configuration; inheriting plugin configuration from a parent POM that already sets one flag and adding the other in the child.","solutions":["Keep exactly one flag true per execution: <addCompileSourceRoot>true</addCompileSourceRoot> for main sources, <addTestCompileSourceRoot>true</addTestCompileSourceRoot> for test sources.","If you need generated code in both main and test, define two executions with separate <output> directories and one flag each, then let test code depend on the main generated classes.","In inherited-config situations, override the unwanted flag to false in the child module."],"exampleFix":"<!-- before -->\n<configuration>\n  <addCompileSourceRoot>true</addCompileSourceRoot>\n  <addTestCompileSourceRoot>true</addTestCompileSourceRoot>\n</configuration>\n\n<!-- after -->\n<configuration>\n  <addCompileSourceRoot>true</addCompileSourceRoot>\n  <addTestCompileSourceRoot>false</addTestCompileSourceRoot>\n</configuration>","handlingStrategy":"validation","validationCode":"# reject POMs that enable both source-root flags\ngrep -q '<addCompileSourceRoot>true' pom.xml && grep -q '<addTestCompileSourceRoot>true' pom.xml && {\n  echo 'addCompileSourceRoot and addTestCompileSourceRoot are mutually exclusive'; exit 1;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Model main vs test generation as two executions with separate output dirs and one flag each.","Set the unused flag explicitly to false when inheriting configuration from a parent POM.","Add a POM-lint rule for this pair — the failure only surfaces at build time, late in configuration review."],"tags":["openapi-generator","maven","plugin-config","mutually-exclusive-options","source-roots"],"backgroundTag":"mutually-exclusive-config","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}