Groovy无法与GCP库一起使用

时间:2018-11-06 11:02:54

标签: groovy google-cloud-platform

我一直试图将Groovy与GCP Java库集成在一起,但是它一直抱怨缺少GCP JAR库。

我的Groovy代码是:

import static java.lang.String.format;
import static com.google.cloud.storage.Blob;

class GroovyExample {

    String format(Integer i) { 
        System.out.println(i.toString());
        return i.toString();
    }

    static void main(String[] args) {
        assert format('String') == 'String';
        assert new GroovyExample().format(Integer.valueOf(1)) == '1';
    }
}

我用来运行Groovy的命令是:

groovy -cp ./usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/tools/java/lib/java-managed-vm/appengine-java-vmruntime GroovyExample.groovy

通过解决方案来运行此Groovy脚本将大有帮助。

只需添加更多内容并作进一步参考,便可以在我创建的涉及GCP和Groovy的自定义Docker容器中运行它。下面是文件。

FROM google/cloud-sdk:latest
RUN  apt-get update \
  && apt-get install -y wget unzip
CMD ["groovysh"]
ENV GROOVY_HOME /opt/groovy
ENV GROOVY_VERSION 2.5.2
RUN set -o errexit -o nounset \
    && echo "Downloading Groovy" \
    && wget --output-document=groovy.zip "https://dist.apache.org/repos/dist/release/groovy/${GROOVY_VERSION}/distribution/apache-groovy-binary-${GROOVY_VERSION}.zip" \
    \
    && echo "Importing keys listed in http://www.apache.org/dist/groovy/KEYS from key server" \
    && export GNUPGHOME="$(mktemp -d)" \
    && for key in \
        "7FAA0F2206DE228F0DB01AD741321490758AAD6F" \
        "331224E1D7BE883D16E8A685825C06C827AF6B66" \
        "34441E504A937F43EB0DAEF96A65176A0FB1CD0B" \
        "9A810E3B766E089FFB27C70F11B595CEDC4AEBB5" \
        "81CABC23EECA0790E8989B361FF96E10F0E13706" \
    ; do \
        for server in \
            "ha.pool.sks-keyservers.net" \
            "hkp://p80.pool.sks-keyservers.net:80" \
            "pgp.mit.edu" \
        ; do \
            echo "  Trying ${server}"; \
            if gpg --keyserver "${server}" --recv-keys "${key}"; then \
                break; \
            fi; \
        done; \
    done; \
    if [ $(gpg --list-keys | grep -c "pub ") -ne 5 ]; then \
        echo "ERROR: Failed to fetch GPG keys" >&2; \
        exit 1; \
    fi \
    \
    && echo "Checking download signature" \
    && wget --no-verbose --output-document=groovy.zip.asc "https://dist.apache.org/repos/dist/release/groovy/${GROOVY_VERSION}/distribution/apache-groovy-binary-${GROOVY_VERSION}.zip.asc" \
    && gpg --batch --verify groovy.zip.asc groovy.zip \
    && rm --recursive --force "${GNUPGHOME}" \
    && rm groovy.zip.asc \
    \
    && echo "Installing Groovy" \
    && unzip groovy.zip \
    && rm groovy.zip \
    && mv "groovy-${GROOVY_VERSION}" "${GROOVY_HOME}/" \
    && ln --symbolic "${GROOVY_HOME}/bin/grape" /usr/bin/grape \
    && ln --symbolic "${GROOVY_HOME}/bin/groovy" /usr/bin/groovy \
    && ln --symbolic "${GROOVY_HOME}/bin/groovyc" /usr/bin/groovyc \
    && ln --symbolic "${GROOVY_HOME}/bin/groovyConsole" /usr/bin/groovyConsole \
    && ln --symbolic "${GROOVY_HOME}/bin/groovydoc" /usr/bin/groovydoc \
    && ln --symbolic "${GROOVY_HOME}/bin/groovysh" /usr/bin/groovysh \
    && ln --symbolic "${GROOVY_HOME}/bin/java2groovy" /usr/bin/java2groovy \
    \
    && echo "Adding groovy user and group" \
    && groupadd --system --gid 1000 groovy \
    && useradd --system --gid groovy --uid 1000 --shell /bin/bash --create-home groovy \
    && mkdir --parents /home/groovy/.groovy/grapes \
    && chown --recursive groovy:groovy /home/groovy \
    \
    && echo "Symlinking root .groovy to groovy .groovy" \
    && ln -s /home/groovy/.groovy /root/.groovy

Am在命令上方运行:

docker run -ti 8332026e2ddf bash

其中

  

8332026e2ddf

是我的图像的ID。

0 个答案:

没有答案