From 9a92823e9a0f7e0206e54bfd75249a754bbf57a7 Mon Sep 17 00:00:00 2001 From: Samruddhi Khandale Date: Wed, 14 Sep 2022 10:20:02 -0700 Subject: Java: Fix gradle bug - sets GRADLE_USER_HOME incorrectly (#152) * fix gradle bug * modify tests --- src/java/devcontainer-feature.json | 4 +--- src/java/install.sh | 2 -- test/java/install_gradle_and_maven.sh | 8 ++++++++ test/java/install_gradle_and_maven_for_user.sh | 21 +++++++++++++++++++++ test/java/scenarios.json | 16 +++++++++++++++- 5 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 test/java/install_gradle_and_maven_for_user.sh diff --git a/src/java/devcontainer-feature.json b/src/java/devcontainer-feature.json index 8eb83a1..4e7781b 100644 --- a/src/java/devcontainer-feature.json +++ b/src/java/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "java", - "version": "1.0.7", + "version": "1.0.8", "name": "Java (via SDKMAN!)", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/java", "description": "Installs Java, SDKMAN! (if not installed), and needed dependencies.", @@ -41,8 +41,6 @@ }, "containerEnv": { "SDKMAN_DIR": "/usr/local/sdkman", - "GRADLE_USER_HOME": "${HOME}/.gradle", - "M2": "${HOME}/.m2", "JAVA_HOME": "/usr/local/sdkman/candidates/java/current", "PATH": "/usr/local/sdkman/bin:/usr/local/sdkman/candidates/java/current/bin:/usr/local/sdkman/candidates/gradle/current/bin:/usr/local/sdkman/candidates/maven/current/bin:${PATH}" } diff --git a/src/java/install.sh b/src/java/install.sh index 1ff3a67..616a626 100755 --- a/src/java/install.sh +++ b/src/java/install.sh @@ -167,13 +167,11 @@ fi # Install Gradle if [[ "${INSTALL_GRADLE}" = "true" ]] && ! gradle --version > /dev/null; then sdk_install gradle latest - updaterc '[ -z "${GRADLE_USER_HOME}" ] && export GRADLE_USER_HOME=${HOME}/.gradle' fi # Install Maven if [[ "${INSTALL_MAVEN}" = "true" ]] && ! mvn --version > /dev/null; then sdk_install maven latest - updaterc '[ -z "$M2" ] && export M2=$HOME/.m2' fi echo "Done!" diff --git a/test/java/install_gradle_and_maven.sh b/test/java/install_gradle_and_maven.sh index a81dd9e..c6aa3e5 100644 --- a/test/java/install_gradle_and_maven.sh +++ b/test/java/install_gradle_and_maven.sh @@ -5,9 +5,17 @@ set -e # Optional: Import test library source dev-container-features-test-lib +check "user is root" whoami | grep root + check "java" java --version check "gradle" gradle --version + +cd /tmp && gradle init --type basic --dsl groovy --incubating --project-name test +check "GRADLE_USER_HOME exists" ls -la /root | grep ".gradle" + check "maven" mvn --version +cd /tmp && mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false +check "m2 exists" ls -la /root | grep ".m2" # Report result reportResults diff --git a/test/java/install_gradle_and_maven_for_user.sh b/test/java/install_gradle_and_maven_for_user.sh new file mode 100644 index 0000000..c724092 --- /dev/null +++ b/test/java/install_gradle_and_maven_for_user.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +check "user is vscode" whoami | grep vscode + +check "java" java --version +check "gradle" gradle --version + +cd /tmp && gradle init --type basic --dsl groovy --incubating --project-name test +check "GRADLE_USER_HOME exists" ls -la /home/vscode | grep ".gradle" + +check "maven" mvn --version +cd /tmp && mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false +check "m2 exists" ls -la /home/vscode | grep ".m2" + +# Report result +reportResults diff --git a/test/java/scenarios.json b/test/java/scenarios.json index 659a857..82e0795 100644 --- a/test/java/scenarios.json +++ b/test/java/scenarios.json @@ -8,6 +8,20 @@ } } }, + "install_gradle_and_maven_for_user": { + "image": "ubuntu:focal", + "remoteUser": "vscode", + "features": { + "common-utils": { + "username": "vscode" + }, + "java": { + "version": "latest", + "installGradle": true, + "installMaven": true + } + } + }, "install_gradle_and_maven": { "image": "ubuntu:focal", "features": { @@ -18,4 +32,4 @@ } } } -} \ No newline at end of file +} -- cgit v1.2.3