line / armeria

Your go-to microservice framework for any situation, from the creator of Netty et al. You can build any type of microservice leveraging your favorite technologies, including gRPC, Thrift, Kotlin, Retrofit, Reactive Streams, Spring Boot and Dropwizard.
https://armeria.dev
Apache License 2.0
4.81k stars 914 forks source link

Cannot use relocated test library at sub projects caused by NoClassDefFoundError #2115

Open imasahiro opened 5 years ago

imasahiro commented 5 years ago

I've realized we cannot use relocated test library at sub projects (e.g. retrofit2, spring, etc.).

// $ cat retrofit2/src/test/java/com/linecorp/armeria/client/retrofit2/RelocatedTestClassTest.java
package com.linecorp.armeria.client.retrofit2;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;

import com.google.common.util.concurrent.testing.TestingExecutors;

public class RelocatedTestClassTest {
    @Test
    public void completeNormally() {
        assertThat(TestingExecutors.noOpScheduledExecutor()).isNotNull();
    }
}
$ ./gradlew retrofit2:shadedTest 
Configuration on demand is an incubating feature.

> Task :core:compileJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

> Task :core:trimShadedJar
Note: there were 14738 duplicate class definitions.
      (http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass)

> Task :retrofit2:shadedTest
com.linecorp.armeria.client.retrofit2.RelocatedTestClassTest > completeNormally FAILED
    java.lang.NoClassDefFoundError: com/linecorp/armeria/internal/shaded/guava/util/concurrent/testing/TestingExecutors
        at com.linecorp.armeria.client.retrofit2.RelocatedTestClassTest.completeNormally(RelocatedTestClassTest.java:27)

        Caused by:
        java.lang.ClassNotFoundException: com.linecorp.armeria.internal.shaded.guava.util.concurrent.testing.TestingExecutors
            at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
            at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
            at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
            ... 1 more
imasahiro commented 5 years ago

Actually, it is not an armeria side issue. Should I open a ticket at https://github.com/line/gradle-scripts instead?

trustin commented 5 years ago

Currently, only the libraries that are part of the module with trim tag can be shaded and trimmed correctly. In that case, you have to put guava-testing to the common dependencies in /build.gradle and set up relocation in dependencies.yml.

trustin commented 5 years ago

I guess the problem is that guava-testing shares the package namespace with guava. :sob:

imasahiro commented 5 years ago

I see. TBH, in my case, the original issue was happened at curator-framework (and curator-test). And since these curator packages share the package namespace, it happened same issue...