microsoft / vscode-dev-containers

NOTE: Most of the contents of this repository have been migrated to the new devcontainers GitHub org (https://github.com/devcontainers). See https://github.com/devcontainers/template-starter and https://github.com/devcontainers/feature-starter for information on creating your own!
https://aka.ms/vscode-remote
MIT License
4.72k stars 1.41k forks source link

gradle fails with `Failed to load native library 'libnative-platform.so' for Linux amd64` #1628

Closed baywet closed 1 year ago

baywet commented 1 year ago

Steps to Reproduce:

  1. Configure the dev container for java variant 17 or 17-bullseye, node lts, install maven false install gradle true. features github cli latest, powershell latest
  2. Build and start the container (reopen in dev container)
  3. type "gradle -v" in the shell

The following error happens

Failed to load native library 'libnative-platform.so' for Linux amd64

Full configuration:

{
    "name": "Java",
    "build": {
        "dockerfile": "Dockerfile",
        "args": {
            // Update the VARIANT arg to pick a Java version: 11, 17
            // Append -bullseye or -buster to pin to an OS version.
            // Use the -bullseye variants on local arm64/Apple Silicon.
            "VARIANT": "17",
            // Options
            "INSTALL_MAVEN": "false",
            "INSTALL_GRADLE": "true",
            "NODE_VERSION": "lts/*"
        }
    },

    // Configure tool-specific properties.
    "customizations": {
        // Configure properties specific to VS Code.
        "vscode": {
            // Set *default* container specific settings.json values on container create.
            "settings": { 
            },

            // Add the IDs of extensions you want installed when the container is created.
            "extensions": [
                "editorconfig.editorconfig",
                "github.copilot",
                "github.vscode-pull-request-github",
                "donjayamanne.githistory",
                "waderyan.gitblame",
                "streetsidesoftware.code-spell-checker",
                "ms-vsliveshare.vsliveshare",
                "esbenp.prettier-vscode",
                "shengchen.vscode-checkstyle",
                "vscjava.vscode-java-pack",
                "vscjava.vscode-gradle",
                "DavidAnson.vscode-markdownlint"
            ]
        }
    },

    // Use 'forwardPorts' to make a list of ports inside the container available locally.
    // "forwardPorts": [],

    // Use 'postCreateCommand' to run commands after the container is created.
    // "postCreateCommand": "java -version",

    // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
    "remoteUser": "vscode",
    "features": {
        "github-cli": "latest",
        "powershell": "latest"
    }
}
# [Choice] Java version (use -bullseye variants on local arm64/Apple Silicon): 11, 17, 11-bullseye, 17-bullseye, 11-buster, 17-buster
ARG VARIANT=11-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/java:${VARIANT}

# [Option] Install Maven
ARG INSTALL_MAVEN="false"
ARG MAVEN_VERSION=""
# [Option] Install Gradle
ARG INSTALL_GRADLE="false"
ARG GRADLE_VERSION=""
RUN if [ "${INSTALL_MAVEN}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install maven \"${MAVEN_VERSION}\""; fi \
    && if [ "${INSTALL_GRADLE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install gradle \"${GRADLE_VERSION}\""; fi

# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
ARG NODE_VERSION="none"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
#     && apt-get -y install --no-install-recommends <your-package-list-here>

# [Optional] Uncomment this line to install global node packages.
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
ChriFo commented 1 year ago

Adding the following lines to devcontainer.json fixed it for me.

 "containerEnv": {
    "GRADLE_USER_HOME": "/home/vscode/.gradle"
}
baywet commented 1 year ago

confirmed! Thanks for sharing this! Do you want to send out the PR or shall I? https://github.com/microsoft/vscode-dev-containers/tree/main/containers/java

baywet commented 1 year ago

(although after running gradle build, it created a $HOME directory at the root of the repo)

ChriFo commented 1 year ago

@baywet sorry, I adjusted my answer before your anwsers to a fully-qualified path because of the issue you described.

Feel free to open PR.

baywet commented 1 year ago

authored #1632. The bug was subtle between user changed in the script and variables being interpreted too early thus yielding no value.

baywet commented 1 year ago

It took me a while to revert to this but now (1.73.1) if you go through the creation of the container experience again with the same arguments it'll give you this instead.

{
    "name": "Java",
    "image": "mcr.microsoft.com/devcontainers/java:17",
    "features": {
        "ghcr.io/devcontainers/features/java:1": {
            "version": "none",
            "installMaven": "true",
            "installGradle": "true"
        },
        "ghcr.io/devcontainers/features/node:1": {
            "version": "lts"
        },
        "ghcr.io/devcontainers/features/github-cli:1": {},
        "ghcr.io/devcontainers/features/powershell:1": {}
    }

    // Use 'forwardPorts' to make a list of ports inside the container available locally.
    // "forwardPorts": [],

    // Use 'postCreateCommand' to run commands after the container is created.
    // "postCreateCommand": "java -version",

    // Configure tool-specific properties.
    // "customizations": {},

    // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
    // "remoteUser": "root"
}

(without a dockerfile) While it takes significantly longer to build, it also works from the get-go. Which means no changes are required to the base dockerfile anymore. Closing.