gradle建立本地作品。在码头集装箱中它没有。为什么? [英] gradle build local works. In docker container it doesn't. WHY?

查看:257
本文介绍了gradle建立本地作品。在码头集装箱中它没有。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况很简单:

这里是我的本地环境:

  cbongiorno at wa-cbongiorno-mba in / Volumes / dev / sterling / java-user-login-service on master [!$] 
$ gradle -v

--- -------------------------------------------------- -------
Gradle 4.0
--------------------------------- ---------------------------

生成时间:2017-06-14 15:11:08 UTC
修订版:316546a5fcb4e2dfe1d6aa0b73a4e09e8cecb5a5

Groovy:2.4.11
Ant:Apache Ant(TM)1.9.6版于2015年6月29日编译
JVM:1.8.0_131(Oracle Corporation 25.131-b11)
操作系统:Mac OS X 10.12.5 x86_64

这里是build命令我运行:

  gradle compileJava检查汇编&&历史|尾巴-3 

这里是结果:

 在3m 3s中创建成功
38个可执行任务:38个执行
1496 gradle clean
1497 gradle compileJava检查汇编&&历史|尾巴-2

现在,当我在docker中运行这个相同的安排时:

 码头运行 -  rm gradle:高山gradle -v 

-------------- ----------------------------------------------
Gradle 4.0
-------------------------------------------- ----------------

生成时间:2017-06-14 15:11:08 UTC
版本:316546a5fcb4e2dfe1d6aa0b73a4e09e8cecb5a5

Groovy:2.4.11
Ant:Apache Ant(TM)版本1.9.6于2015年6月29日编译
JVM:1.8.0_131(Oracle Corporation 25.131-b11)
操作系统: Linux 4.9.36-moby amd64

docker run --rm -v$ PWD:/ project -w / project gradle:alpine gradle compileJava check汇编

测试失败,并在日志中显示:

 由:java.lang.NoClassDefFoundError引起:无法初始化类org.xerial.snappy.Snappy 
build_1 | at org.redisson.codec.SnappyCodec $ 2.encode(SnappyCodec.java:68)
build_1 |在org.redisson.client.handler.CommandEncoder.encode(CommandEncoder.java:103)
build_1 |在org.redisson.client.handler.CommandEncoder.encode(CommandEncoder.java:45)
build_1 |在io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:107)
build_1 | ... 31更多
build_1 |
build_1 |
build_1 | io.netty.handler.codec.EncoderException:java.lang.NoClassDefFoundError:无法初始化类org.xerial.snappy.Snappy

当我的应用程序尝试与Redis进行互动时。



这究竟有多可能?这是一个红鲱鱼,问题与码头环境本身有关吗?我猜想归档文件是损坏/错误的,但码头容器会从相同的工件存储库中提取。所以,我甚至不知道从哪里开始



我使用了

解决方案

Java对Snappy的本地库(通过JNI加载)是针对glibc编译的。 Alpine Linux(你的容器是基于什么的)使用musl libc,它是源代码兼容的但不是二进制兼容的(基本上意味着如果你编译本地库反对musl它会起作用,但是如果它是针对glibc编译的,它将不起作用您有三种选择:


  1. 安装<$ c

    $ c> java-snappy-native (其中包含为musl构建的本地库),并将 org.xerial.snappy.use.systemlib = true code>(告诉Java库使用预先安装的本地lbrary)。 目前您还需要安装 snappy ,因为有人未能将该依赖关系添加到上述软件包中。


  2. 使用带有glibc的基础容器

  3. 在您的Alpine容器中安装glibc(不推荐)


The situation is simple:

here is my local env:

cbongiorno at wa-cbongiorno-mba in /Volumes/dev/sterling/java-user-login-service on master [!$]
$ gradle -v

------------------------------------------------------------
Gradle 4.0
------------------------------------------------------------

Build time:   2017-06-14 15:11:08 UTC
Revision:     316546a5fcb4e2dfe1d6aa0b73a4e09e8cecb5a5

Groovy:       2.4.11
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_131 (Oracle Corporation 25.131-b11)
OS:           Mac OS X 10.12.5 x86_64

here is the build command I run:

gradle compileJava check assemble && history | tail -3

here are the results:

BUILD SUCCESSFUL in 3m 3s
38 actionable tasks: 38 executed
 1496  gradle clean
 1497  gradle compileJava check assemble && history | tail -2

Now, when I run this identical arrangement in docker:

docker run --rm gradle:alpine gradle -v

------------------------------------------------------------
Gradle 4.0
------------------------------------------------------------

Build time:   2017-06-14 15:11:08 UTC
Revision:     316546a5fcb4e2dfe1d6aa0b73a4e09e8cecb5a5

Groovy:       2.4.11
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_131 (Oracle Corporation 25.131-b11)
OS:           Linux 4.9.36-moby amd64

docker run --rm -v "$PWD":/project -w /project gradle:alpine gradle compileJava check assemble

The tests fail and in the logs I get:

Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.xerial.snappy.Snappy
build_1  |      at org.redisson.codec.SnappyCodec$2.encode(SnappyCodec.java:68)
build_1  |      at org.redisson.client.handler.CommandEncoder.encode(CommandEncoder.java:103)
build_1  |      at org.redisson.client.handler.CommandEncoder.encode(CommandEncoder.java:45)
build_1  |      at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:107)
build_1  |      ... 31 more
build_1  | 
build_1  | 
build_1  |     io.netty.handler.codec.EncoderException: java.lang.NoClassDefFoundError: Could not initialize class org.xerial.snappy.Snappy

When my app attempts to engage with Redis.

How on earth is this possible? Is this a red-herring and the issues is related to the docker environment itself? I would guess an archive is corrupt/wrong but the docker container would pull from the same artifact repositories. So, I don't even know where to start

I used the answer from here to dump the hash values of every jar into a file with:

docker run --rm -v "$PWD":/project -w /project  gradle:alpine gradle printDependencyHashes | sort >  hashes-docker.log

gradle printDependencyHashes | sort > hashes.log

respectively. The results are identical. I even thought about how jar load order from the files system could effect class loading and compared dependencies. Identical. Omitted for brevity.

解决方案

Java Snappy's native library (loaded through JNI) is compiled against glibc. Alpine Linux (what your container is based on) uses the musl libc which is source-compatible but not binary-compatible (basically means if you compile the native library against musl it will work, but if it is compiled against glibc it will not work with musl).

You have three options:

  1. Install java-snappy-native (which contains a native library built for musl) in your Alpine container and set org.xerial.snappy.use.systemlib=true (tells the Java library to use the preinstalled native lbrary). Currently you also need to install snappy since somebody failed to add that dependency to the above package.
  2. Use a base container with glibc
  3. Install glibc in your Alpine container (not really recommended)

这篇关于gradle建立本地作品。在码头集装箱中它没有。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆