diff --git a/cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java b/cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java index 0a87eb864..361e3a0b2 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java +++ b/cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java @@ -445,6 +445,19 @@ default String getMavenArgs() { } + /** + * @return the String value for the variable M2_REPO, or null if called outside an IDEasy installation. + */ + default String getMavenRepoEnvVariable() { + + if (getIdeHome() != null) { + Path m2Repo = getConfPath().resolve(Mvn.M2_CONFIG_FOLDER).resolve("repository"); + return m2Repo.toString(); + } + return null; + + } + /** * Updates the current working directory (CWD) and configures the environment paths according to the specified parameters. This method is central to changing * the IDE's notion of where it operates, affecting where configurations, workspaces, settings, and other resources are located or loaded from. diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/mvn/Mvn.java b/cli/src/main/java/com/devonfw/tools/ide/tool/mvn/Mvn.java index 66132d649..607b513fb 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/tool/mvn/Mvn.java +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/mvn/Mvn.java @@ -33,7 +33,8 @@ public class Mvn extends PluginBasedCommandlet { /** The name of the settings.xml */ public static final String SETTINGS_FILE = "settings.xml"; - private static final String M2_CONFIG_FOLDER = ".m2"; + /** The name of the m2 repository */ + public static final String M2_CONFIG_FOLDER = ".m2"; private static final String SETTINGS_SECURITY_FILE = "settings-security.xml"; diff --git a/cli/src/main/java/com/devonfw/tools/ide/variable/IdeVariables.java b/cli/src/main/java/com/devonfw/tools/ide/variable/IdeVariables.java index 396939a53..059f8b9fd 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/variable/IdeVariables.java +++ b/cli/src/main/java/com/devonfw/tools/ide/variable/IdeVariables.java @@ -41,9 +41,12 @@ public interface IdeVariables { /** {@link VariableDefinition} for version of maven (mvn). */ VariableDefinitionVersion MVN_VERSION = new VariableDefinitionVersion("MVN_VERSION", "MAVEN_VERSION"); - /** {@link VariableDefinition} arguments for maven to set the m2 repo location. */ + /** {@link VariableDefinition} arguments for maven to locate the settings file. */ VariableDefinitionString MAVEN_ARGS = new VariableDefinitionString("MAVEN_ARGS", null, c -> c.getMavenArgs(), false, true); + /** {@link VariableDefinition} arguments for maven to set the m2 repo location. */ + VariableDefinitionString M2_REPO = new VariableDefinitionString("M2_REPO", null, c -> c.getMavenRepoEnvVariable(), false, true); + /** {@link VariableDefinition} for {@link com.devonfw.tools.ide.context.IdeContext#getWorkspaceName() WORKSPACE}. */ VariableDefinitionString DOCKER_EDITION = new VariableDefinitionString("DOCKER_EDITION", null, c -> "rancher"); @@ -58,7 +61,7 @@ public interface IdeVariables { /** A {@link Collection} with all pre-defined {@link VariableDefinition}s. */ Collection> VARIABLES = List.of(PATH, HOME, WORKSPACE_PATH, IDE_HOME, IDE_ROOT, WORKSPACE, IDE_TOOLS, CREATE_START_SCRIPTS, - IDE_MIN_VERSION, MVN_VERSION, DOCKER_EDITION, JASYPT_OPTS, MAVEN_ARGS, PROJECT_NAME); + IDE_MIN_VERSION, MVN_VERSION, M2_REPO, DOCKER_EDITION, JASYPT_OPTS, MAVEN_ARGS, PROJECT_NAME); /** * @param name the name of the requested {@link VariableDefinition}.