testcontainers / testcontainers-scala

Docker containers for testing in scala
MIT License
629 stars 126 forks source link

Compilation problems when using GenericContainer #11

Closed zaharidichev closed 6 years ago

zaharidichev commented 6 years ago

@dimafeng

The moment I touch GenericContainer class I get the following errors:

[error] Class org.testcontainers.shaded.javax.annotation.CheckForNull not found - continuing with a stub.
[error] Class org.testcontainers.shaded.javax.annotation.CheckForNull not found - continuing with a stub.
[error] Class org.testcontainers.shaded.javax.annotation.CheckForNull not found - continuing with a stub.

[error] Class org.testcontainers.shaded.javax.annotation.CheckForNull not found - continuing with a stub.
[error] Class org.testcontainers.shaded.javax.annotation.CheckForNull not found - continuing with a stub.
[error] Class org.testcontainers.shaded.javax.annotation.CheckForNull not found - continuing with a stub.

Scala Version: 2.11.8 Sbt version: 0.13.8

Have tried changing scala and sbt versions without much success. This error really does not tell me much of what I need (e.g. where is this class needed at all ?). Is this some conflict with other libraries. For example is lombock's NonNull getting mixed up with findbug's NonNull. If that is the case I have excluded the latter dependency but still get errors. A bit of help will be greatly appreciated

dimafeng commented 6 years ago

Hi @zaharidichev I'll take a look tonight or tomorrow.

zaharidichev commented 6 years ago

Thanks a lot. It really is causing me quite a lot of headache :(

dimafeng commented 6 years ago

@zaharidichev could you please show the list of your dependencies and their versions?

zaharidichev commented 6 years ago

@dimafeng Thanks for looking into that. Following is a list of the dependencies.

ch.qos.logback.logback.classic.1.1.1
ch.qos.logback.logback.core.1.1.1
com.beust.jcommander.1.12
com.dimafeng.testcontainers.scala.0.11.0
com.fasterxml.jackson.core.jackson.annotations.2.3.2
com.fasterxml.jackson.core.jackson.annotations.2.7.8
com.fasterxml.jackson.core.jackson.core.2.3.2
com.fasterxml.jackson.core.jackson.core.2.7.8
com.fasterxml.jackson.core.jackson.databind.2.3.2
com.fasterxml.jackson.core.jackson.databind.2.7.8
com.fasterxml.jackson.datatype.jackson.datatype.jdk8.2.7.8
com.fasterxml.jackson.datatype.jackson.datatype.jsr310.2.7.8
com.github.fakemongo.fongo.2.0.11
com.github.jnr.jffi.1.2.15
com.github.jnr.jffi.1.2.15.native
com.github.jnr.jnr.constants.0.9.8
com.github.jnr.jnr.ffi.2.1.4
com.github.jnr.jnr.posix.3.0.41
com.github.jnr.jnr.x86asm.1.0.2
com.github.nscala.time.nscala.time.1.0.0
com.google.guava.guava.18.0
com.googlecode.disruptor.disruptor.2.10.4
com.kohlschutter.junixsocket.junixsocket.common.2.0.4
com.kohlschutter.junixsocket.junixsocket.native.common.2.0.4
com.twitter.scrooge.core.3.17.0
com.typesafe.akka.akka.actor.2.3.4
com.typesafe.akka.akka.testkit.2.3.4
com.typesafe.config.1.2.1
com.typesafe.config.1.3.0
com.typesafe.play.play.datacommons.2.3.10
com.typesafe.play.play.datacommons.2.5.10
com.typesafe.play.play.functional.2.3.10
com.typesafe.play.play.functional.2.5.10
com.typesafe.play.play.iteratees.2.3.10
com.typesafe.play.play.iteratees.2.5.10
com.typesafe.play.play.json.2.3.10
com.typesafe.play.play.json.2.5.10
com.vividsolutions.jts.1.13
commons.cli.commons.cli.1.1
commons.codec.commons.codec.1.10
commons.io.commons.io.2.5
commons.lang.commons.lang.2.5
commons.lang.commons.lang.2.6
de.grundid.opendatalab.geojson.jackson.1.2
joda.time.joda.time.2.3
joda.time.joda.time.2.9.6
junit.junit.4.12
org.apache.commons.commons.compress.1.12
org.apache.commons.commons.lang3.3.3.2
org.apache.thrift.libthrift.0.8.0
org.aspectj.aspectjrt.1.8.6
org.beanshell.bsh.2.0b4
org.bouncycastle.bcprov.jdk15on.1.54
org.hamcrest.hamcrest.core.1.3
org.jetbrains.annotations.13.0
org.joda.joda.convert.1.6
org.joda.joda.convert.1.8.1
org.mockito.mockito.all.1.9.5
org.mongodb.casbah.commons.3.1.1
org.mongodb.casbah.core.3.1.1
org.mongodb.casbah.query.3.1.1
org.mongodb.mongo.java.driver.3.2.2
org.mozilla.rhino.1.7.7.1
org.ow2.asm.asm.5.0.3
org.ow2.asm.asm.analysis.5.0.3
org.ow2.asm.asm.commons.5.0.3
org.ow2.asm.asm.tree.5.0.3
org.ow2.asm.asm.util.5.0.3
org.rnorth.duct.tape.duct.tape.1.0.6
org.rnorth.tcp.unix.socket.proxy.1.0.1
org.rnorth.visible.assertions.visible.assertions.2.0.0
org.scala.lang.modules.scala.parser.combinators.1.0.4
org.scala.lang.modules.scala.xml.1.0.5
org.scala.lang.scala.library.8
org.scala.lang.scala.reflect.1
org.scala.lang.scala.reflect.7
org.scala.lang.scala.reflect.8
org.scala.sbt.test.interface.1.0
org.scala.stm.scala.stm.0.7
org.scalacheck.scalacheck.1.11.3
org.scalactic.scalactic.3.0.1
org.scalatest.scalatest.3.0.1
org.scijava.native.lib.loader.2.0.2
org.scoverage.scalac.scoverage.plugin.1.1.0
org.scoverage.scalac.scoverage.runtime.1.1.0
org.slf4j.jcl.over.slf4j.1.7.21
org.slf4j.slf4j.api.1.7.13
org.slf4j.slf4j.api.1.7.25
org.slf4j.slf4j.ext.1.7.25
org.testcontainers.testcontainers.1.4.3
org.testng.testng.6.1.1
org.yaml.snakeyaml.1.6
org.zeroturnaround.zt.exec.1.8
dimafeng commented 6 years ago

@zaharidichev I checked codebase of org.testcontainers.testcontainers.1.4.3 and didn't find any usages of the org.testcontainers.shaded.javax.annotation.CheckForNull as well as there are no usages in testcontainers-scala. Could you please try to switch to a DEBUG level of compilation logging? The answer may be there, we need to find out where that class is accessed from.

zaharidichev commented 6 years ago

I did try setting:

scalacOptions ++= Seq("-unchecked", "-feature", "-explaintypes", "-print-types")

However that did not display any additional information. Quite strange. Just the same old error. Something is getting severely mixed up on the compiler level. This type does not even exist. I do not understand what and why is trying to access it.

dimafeng commented 6 years ago

I'll try to create an SBT project to reproduce the issue.

zaharidichev commented 6 years ago

@dimafeng Interestingly enough, we are using your library in another project and it does not show such problems. I am not sure what is so special with this one and this set of dependencies that causes so much headache. Same version of scala, same version of sbt

zaharidichev commented 6 years ago

Right... So @dimafeng running the compiler in verbose mode yields the following:

[info] [loaded package loader jackson in 0ms]
[info] [loaded package loader annotation in 0ms]
[info] [loaded package loader javax in 0ms]
[error] Class org.testcontainers.shaded.javax.annotation.CheckForNull not found - continuing with a stub.
[error] Class org.testcontainers.shaded.javax.annotation.CheckForNull not found - continuing with a stub.
[error] Class org.testcontainers.shaded.javax.annotation.CheckForNull not found - continuing with a stub.
[info] [loaded class file /Users/zahari/.ivy2/cache/org.testcontainers/testcontainers/jars/testcontainers-1.4.3.jar(com/github/dockerjava/api/command/InspectContainerResponse.class) in 2ms]
[info] [loaded package loader traits in 0ms]

This is happening right before the loader picks up InspectContainerResponse. Looking a bit further into that class, it looks like (an excerpt):

import org.testcontainers.shaded.com.fasterxml.jackson.annotation.JsonIgnore;
import org.testcontainers.shaded.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.testcontainers.shaded.com.fasterxml.jackson.annotation.JsonProperty;
import org.testcontainers.shaded.javax.annotation.CheckForNull; <----- this guy here !

@JsonIgnoreProperties(
    ignoreUnknown = true
)
public class InspectContainerResponse {
    @JsonProperty("Args")
    private String[] args;
    @JsonProperty("Config")

There is no such class org.testcontainers.shaded.javax.annotation.CheckForNull in the test containers jar on my classpath. For reference, I am currently running that with:

Seems like they missed something while shading the javax or I am getting confused somehow

dimafeng commented 6 years ago

@zaharidichev sorry for the late response. This is interesting.

@rnorth @bsideup do you guys know where org.testcontainers.shaded.javax.annotation.CheckForNull should come from?

bsideup commented 6 years ago

@dimafeng I think I know where it comes from... Not related to testcontainers-scala, we need to fix that in testcontainers-core.

@zaharidichev thanks for reporting!

zaharidichev commented 6 years ago

@bsideup Is there any estimation of when would that get fixed so I can pull in a snapshot at least. Alternatively I can give yo a hand and prepare a PR for it.

ljkr commented 6 years ago

I have the same problem. @zaharidichev, did you fixed or worked-around the issue on your side?

dimafeng commented 6 years ago

@ljkr sorry to hear that. It seems that issue was fixed in the latest version of testcontainers-java. I'll release a new version of testcontainers-scala with that fix later today.

dimafeng commented 6 years ago

@ljkr @zaharidichev please try version 0.13.0

ljkr commented 6 years ago

@dimafeng the same problem with 0.13.0

org.testcontainers:testcontainers does not contain dependency on jsr-305 where CheckForNull comes from.

So adding jsr-305 (see below) to the project should fix the issue.

diff --git a/core/pom.xml b/core/pom.xml
index 00cc48d..f3eadf8 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -27,6 +27,12 @@
             <version>1.7.25</version>
         </dependency>

+        <dependency>
+            <groupId>com.google.code.findbugs</groupId>
+            <artifactId>jsr305</artifactId>
+            <version>3.0.2</version>
+        </dependency>
+
         <dependency>
             <groupId>com.github.docker-java</groupId>
             <artifactId>docker-java</artifactId>
@@ -222,7 +228,7 @@
                             <include>org.apache.httpcomponents:*</include>
                             <include>org.glassfish.*:*</include>
                             <include>org.aopalliance.*:*</include>
-                            <include>javax.annotation:*</include>
+                            <include>com.google.code.findbugs:*</include>
                             <include>javax.inject:*</include>
                             <include>javax.ws.rs:*</include>
                             <include>com.fasterxml.*:*</include>
dimafeng commented 6 years ago

@ljkr @zaharidichev should be fixed in testcontainers-scala 0.14.0, please try - https://github.com/testcontainers/testcontainers-java/pull/563 was released in testcontainers-java 1.6.0