gradle依赖性问题

eufgjt7s  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(245)

我的最终目标是运行netflix karyon示例https://medium.com/@sarinduudagepala/introduction-收件人:netflix-karyon-266f9ae032fb
我对grad尔和卡里恩还不熟悉。所以,在开始讨论太多未知的问题之前,我用gradle做了一个例子,它使用了jackson依赖关系并将json对象封送到文件。它还使用自定义gradle任务来执行应用程序。效果很好。
任务

ext {
   javaMainClass = "TestGradle.Library"
}

task runWithJavaExec(type: JavaExec) {
    group = "Execution"
    description = "Run the main class with JavaExecTask"
    classpath = sourceSets.main.runtimeClasspath
    main = javaMainClass
}

在本例中,很明显gradle自定义任务正在处理外部依赖项。
现在,当我在链接中尝试这个例子时,我得到了如下错误

/Users/renjithr/WORK/LEARN/TestGradle/src/main/java/TestGradle/PingPongResource.java:3: error: package javax.ws.rs does not exist
import javax.ws.rs.GET;
                  ^
/Users/renjithr/WORK/LEARN/TestGradle/src/main/java/TestGradle/PingPongResource.java:4: error: package javax.ws.rs does not exist
import javax.ws.rs.Path;
                  ^
/Users/renjithr/WORK/LEARN/TestGradle/src/main/java/TestGradle/PingPongResource.java:5: error: package javax.ws.rs does not exist
import javax.ws.rs.Produces;
                  ^
/Users/renjithr/WORK/LEARN/TestGradle/src/main/java/TestGradle/PingPongResource.java:6: error: package javax.ws.rs.core does not exist
import javax.ws.rs.core.MediaType;
                       ^
/Users/renjithr/WORK/LEARN/TestGradle/src/main/java/TestGradle/PingPongResource.java:7: error: package javax.ws.rs.core does not exist
import javax.ws.rs.core.Response;
                       ^
/Users/renjithr/WORK/LEARN/TestGradle/src/main/java/TestGradle/PingPongResource.java:9: error: package com.google.inject does not exist
import com.google.inject.Singleton;
                        ^
/Users/renjithr/WORK/LEARN/TestGradle/src/main/java/TestGradle/PingPongResource.java:11: error: cannot find symbol
@Singleton
 ^
  symbol: class Singleton
/Users/renjithr/WORK/LEARN/TestGradle/src/main/java/TestGradle/PingPongResource.java:12: error: cannot find symbol
@Path("/ping")
 ^
  symbol: class Path
/Users/renjithr/WORK/LEARN/TestGradle/src/main/java/TestGradle/PingPongResource.java:16: error: cannot find symbol
        public Response getTopics() {
               ^
  symbol:   class Response
  location: class PingPongResource
/Users/renjithr/WORK/LEARN/TestGradle/src/main/java/TestGradle/Library.java:12: error: package com.fasterxml.jackson.databind does not exist
import com.fasterxml.jackson.databind.ObjectMapper;
                                     ^
/Users/renjithr/WORK/LEARN/TestGradle/src/main/java/TestGradle/BootstrapInjectionModule.java:3: error: package com.netflix.governator.annotations does not exist
import com.netflix.governator.annotations.Modules;
                                         ^
/Users/renjithr/WORK/LEARN/TestGradle/src/main/java/TestGradle/BootstrapInjectionModule.java:6: error: package netflix.karyon does not exist
import netflix.karyon.KaryonBootstrap;
                     ^
/Users/renjithr/WORK/LEARN/TestGradle/src/main/java/TestGradle/BootstrapInjectionModule.java:7: error: package netflix.karyon does not exist
import netflix.karyon.ShutdownModule;
                     ^
/Users/renjithr/WORK/LEARN/TestGradle/src/main/java/TestGradle/BootstrapInjectionModule.java:12: error: cannot find symbol
@KaryonBootstrap(name = "pingpong-service")
 ^
  symbol: class KaryonBootstrap
/Users/renjithr/WORK/LEARN/TestGradle/src/main/java/TestGradle/BootstrapInjectionModule.java:13: error: cannot find symbol
@Modules(include = {
 ^
  symbol: class Modules
/Users/renjithr/WORK/LEARN/TestGradle/src/main/java/TestGradle/BootstrapInjectionModule.java:20: error: cannot access KaryonHttpModule
        class KaryonJerseyModuleImpl extends KaryonJerseyModule{
        ^
  class file for netflix.karyon.transport.http.KaryonHttpModule not found
/Users/renjithr/WORK/LEARN/TestGradle/src/main/java/TestGradle/PingPongResource.java:14: error: cannot find symbol
        @GET
         ^
  symbol:   class GET
  location: class PingPongResource
/Users/renjithr/WORK/LEARN/TestGradle/src/main/java/TestGradle/PingPongResource.java:15: error: cannot find symbol
        @Produces(MediaType.APPLICATION_JSON)
         ^
  symbol:   class Produces
  location: class PingPongResource
/Users/renjithr/WORK/LEARN/TestGradle/src/main/java/TestGradle/PingPongResource.java:17: error: cannot find symbol
                return Response.ok("{\"Response\" : \"Pong\"}").build();
                       ^
  symbol:   variable Response
  location: class PingPongResource
/Users/renjithr/WORK/LEARN/TestGradle/src/main/java/TestGradle/Library.java:20: error: cannot find symbol
        ObjectMapper mapper = new ObjectMapper();
        ^
  symbol:   class ObjectMapper
  location: class Library
/Users/renjithr/WORK/LEARN/TestGradle/src/main/java/TestGradle/Library.java:20: error: cannot find symbol
        ObjectMapper mapper = new ObjectMapper();
                                  ^
  symbol:   class ObjectMapper
  location: class Library
/Users/renjithr/WORK/LEARN/TestGradle/src/main/java/TestGradle/BootstrapInjectionModule.java:22: error: method does not override or implement a method from a supertype
                @Override
                ^
/Users/renjithr/WORK/LEARN/TestGradle/src/main/java/TestGradle/BootstrapInjectionModule.java:24: error: cannot find symbol
                        server().port(8888).threadPoolSize(100);
                        ^
  symbol:   method server()
  location: class BootstrapInjectionModule.KaryonJerseyModuleImpl
23 errors

构建.gradle

plugins {
    // Apply the java-library plugin to add support for Java Library
    id 'java-library'
    id 'application'
}

repositories {
    // Use jcenter for resolving dependencies.
    // You can declare any Maven/Ivy/file repository here.
    mavenCentral()
}

dependencies {
    // This dependency is exported to consumers, that is to say found on their compile classpath.
    api 'org.apache.commons:commons-math3:3.6.1'

    // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
    //compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.10.2'
    // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
    //compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.10.2'

    compile group: 'com.netflix.karyon', name: 'karyon2-admin-web', version: '2.7.1'
    compile group: 'com.netflix.karyon', name: 'karyon2-jersey-blocking', version:'2.7.1'
    compile group: 'com.netflix.karyon', name: 'karyon2-archaius', version: '2.7.1'

    implementation 'com.google.guava:guava:28.0-jre'

    // Use JUnit test framework
    testImplementation 'junit:junit:4.12'
}

ext {
   //javaMainClass = "TestGradle.Library"
}

task runWithJavaExec(type: JavaExec) {
    /*group = "Execution"
    description = "Run the main class with JavaExecTask"
    classpath = sourceSets.main.runtimeClasspath
    main = javaMainClass*/
    group = "Execution"
    description = "Run Sample Ping Pong Application"

    main = "netflix.karyon.KaryonRunner"
    print  sourceSets.main.runtimeClasspath
    classpath = sourceSets.main.runtimeClasspath

    jvmArgs "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"
    systemProperty 'java.awt.headless', 'true'
    systemProperty 'archaius.deployment.environment', 'dev'

    args = ["TestGradle.BootstrapInjectionModule"]
}

bootstrapinjectionmodule.java文件

package TestGradle;

import com.netflix.governator.annotations.Modules;

import netflix.adminresources.resources.KaryonWebAdminModule;
import netflix.karyon.KaryonBootstrap;
import netflix.karyon.ShutdownModule;
import netflix.karyon.archaius.ArchaiusBootstrap;
import netflix.karyon.jersey.blocking.KaryonJerseyModule;

@ArchaiusBootstrap
@KaryonBootstrap(name = "pingpong-service")
@Modules(include = {
        ShutdownModule.class,
        KaryonWebAdminModule.class,
        BootstrapInjectionModule.KaryonJerseyModuleImpl.class
})
public class BootstrapInjectionModule {

    class KaryonJerseyModuleImpl extends KaryonJerseyModule{

        @Override
        protected void configureServer() {
            server().port(8888).threadPoolSize(100);
        }

    }

}

乒乓球源

package TestGradle;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.google.inject.Singleton;

@Singleton
@Path("/ping")
public class PingPongResource {
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Response getTopics() {
        return Response.ok("{\"Response\" : \"Pong\"}").build();
    }
}

我不知道这跟卡里恩有没有关系。看起来像是gradle的类路径问题。请帮忙。
更新****
发布依赖关系树以备不时之需

> Configure project :
file collection
> Task :dependencies

------------------------------------------------------------
Root project
------------------------------------------------------------

annotationProcessor - Annotation processors and their dependencies for source set 'main'.
No dependencies

api - API dependencies for source set 'main'. (n)
\--- org.apache.commons:commons-math3:3.6.1 (n)

apiElements - API elements for main. (n)
No dependencies

archives - Configuration for archive artifacts. (n)
No dependencies

compileClasspath - Compile classpath for source set 'main'.
+--- org.apache.commons:commons-math3:3.6.1
+--- com.fasterxml.jackson.core:jackson-core:2.10.2
+--- com.fasterxml.jackson.core:jackson-databind:2.10.2
|    +--- com.fasterxml.jackson.core:jackson-annotations:2.10.2
|    \--- com.fasterxml.jackson.core:jackson-core:2.10.2
+--- com.netflix.karyon:karyon2-admin-web:2.7.1
+--- com.netflix.karyon:karyon2-jersey-blocking:2.7.1
+--- com.netflix.karyon:karyon2-archaius:2.7.1
\--- com.google.guava:guava:28.0-jre
     +--- com.google.guava:failureaccess:1.0.1
     +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
     +--- com.google.code.findbugs:jsr305:3.0.2
     +--- org.checkerframework:checker-qual:2.8.1
     +--- com.google.errorprone:error_prone_annotations:2.3.2
     +--- com.google.j2objc:j2objc-annotations:1.3
     \--- org.codehaus.mojo:animal-sniffer-annotations:1.17

compileOnly - Compile only dependencies for source set 'main'. (n)
No dependencies

default - Configuration for default artifacts. (n)
No dependencies

implementation - Implementation only dependencies for source set 'main'. (n)
\--- com.google.guava:guava:28.0-jre (n)

runtimeClasspath - Runtime classpath of source set 'main'.
+--- org.apache.commons:commons-math3:3.6.1
+--- com.fasterxml.jackson.core:jackson-core:2.10.2
+--- com.fasterxml.jackson.core:jackson-databind:2.10.2
|    +--- com.fasterxml.jackson.core:jackson-annotations:2.10.2
|    \--- com.fasterxml.jackson.core:jackson-core:2.10.2
+--- com.netflix.karyon:karyon2-admin-web:2.7.1
|    +--- org.freemarker:freemarker:2.3.15
|    +--- org.codehaus.jackson:jackson-mapper-asl:1.9.11
|    |    \--- org.codehaus.jackson:jackson-core-asl:1.9.11
|    +--- org.slf4j:slf4j-api:1.7.7
|    +--- com.netflix.karyon:karyon2-admin:2.7.1
|    |    +--- org.codehaus.jackson:jackson-mapper-asl:1.9.11 (*)
|    |    +--- org.slf4j:slf4j-api:1.7.7
|    |    +--- javax.ws.rs:jsr311-api:1.1.1
|    |    +--- javax.servlet:servlet-api:2.5
|    |    +--- org.mortbay.jetty:jetty:6.1.26
|    |    |    +--- org.mortbay.jetty:jetty-util:6.1.26
|    |    |    \--- org.mortbay.jetty:servlet-api:2.5-20081211
|    |    +--- com.sun.jersey.contribs:jersey-guice:1.9.1 -> 1.18.1
|    |    |    +--- javax.inject:javax.inject:1
|    |    |    +--- com.google.inject:guice:3.0
|    |    |    |    +--- javax.inject:javax.inject:1
|    |    |    |    +--- aopalliance:aopalliance:1.0
|    |    |    |    \--- org.sonatype.sisu.inject:cglib:2.2.1-v20090111
|    |    |    |         \--- asm:asm:3.1
|    |    |    +--- com.google.inject.extensions:guice-servlet:3.0
|    |    |    |    \--- com.google.inject:guice:3.0 (*)
|    |    |    \--- com.sun.jersey:jersey-servlet:1.18.1
|    |    |         \--- com.sun.jersey:jersey-server:1.18.1
|    |    |              \--- com.sun.jersey:jersey-core:1.18.1
|    |    +--- com.sun.jersey:jersey-servlet:1.18.1 (*)
|    |    +--- com.sun.jersey:jersey-server:1.18.1 (*)
|    |    +--- com.google.inject.extensions:guice-servlet:3.0 (*)
|    |    +--- com.netflix.pytheas:pytheas-core:1.25
|    |    |    +--- commons-collections:commons-collections:3.2.1
|    |    |    +--- org.freemarker:freemarker:2.3.15
|    |    |    +--- javax.ws.rs:jsr311-api:1.1.1
|    |    |    +--- commons-codec:commons-codec:1.5 -> 1.6
|    |    |    +--- com.sun.jersey:jersey-core:1.11 -> 1.18.1
|    |    |    +--- org.slf4j:slf4j-api:1.7.7
|    |    |    +--- com.sun.jersey:jersey-json:1.11
|    |    |    |    +--- org.codehaus.jettison:jettison:1.1
|    |    |    |    |    \--- stax:stax-api:1.0.1
|    |    |    |    +--- com.sun.xml.bind:jaxb-impl:2.2.3-1
|    |    |    |    |    \--- javax.xml.bind:jaxb-api:2.2.2
|    |    |    |    |         +--- javax.xml.stream:stax-api:1.0-2
|    |    |    |    |         \--- javax.activation:activation:1.1
|    |    |    |    +--- org.codehaus.jackson:jackson-core-asl:1.9.2 -> 1.9.11
|    |    |    |    +--- org.codehaus.jackson:jackson-mapper-asl:1.9.2 -> 1.9.11 (*)
|    |    |    |    +--- org.codehaus.jackson:jackson-jaxrs:1.9.2
|    |    |    |    |    +--- org.codehaus.jackson:jackson-core-asl:1.9.2 -> 1.9.11
|    |    |    |    |    \--- org.codehaus.jackson:jackson-mapper-asl:1.9.2 -> 1.9.11 (*)
|    |    |    |    +--- org.codehaus.jackson:jackson-xc:1.9.2
|    |    |    |    |    +--- org.codehaus.jackson:jackson-core-asl:1.9.2 -> 1.9.11
|    |    |    |    |    \--- org.codehaus.jackson:jackson-mapper-asl:1.9.2 -> 1.9.11 (*)
|    |    |    |    \--- com.sun.jersey:jersey-core:1.11 -> 1.18.1
|    |    |    +--- commons-beanutils:commons-beanutils:1.8.2
|    |    |    |    \--- commons-logging:commons-logging:1.1.1
|    |    |    +--- com.google.guava:guava:14.0.1 -> 28.0-jre
|    |    |    |    +--- com.google.guava:failureaccess:1.0.1
|    |    |    |    +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
|    |    |    |    +--- com.google.code.findbugs:jsr305:3.0.2
|    |    |    |    +--- org.checkerframework:checker-qual:2.8.1
|    |    |    |    +--- com.google.errorprone:error_prone_annotations:2.3.2
|    |    |    |    +--- com.google.j2objc:j2objc-annotations:1.3
|    |    |    |    \--- org.codehaus.mojo:animal-sniffer-annotations:1.17
|    |    |    +--- com.netflix.archaius:archaius-core:0.5.4 -> 0.6.3
|    |    |    |    +--- com.google.guava:guava:11.0.2 -> 28.0-jre (*)
|    |    |    |    +--- org.codehaus.jackson:jackson-mapper-asl:1.9.11 (*)
|    |    |    |    +--- org.slf4j:slf4j-api:1.6.4 -> 1.7.7
|    |    |    |    +--- commons-configuration:commons-configuration:1.8
|    |    |    |    |    +--- commons-lang:commons-lang:2.6
|    |    |    |    |    \--- commons-logging:commons-logging:1.1.1
|    |    |    |    +--- org.codehaus.jackson:jackson-core-asl:1.9.11
|    |    |    |    \--- com.google.code.findbugs:annotations:2.0.0
|    |    |    +--- javax.servlet:servlet-api:2.5
|    |    |    +--- commons-configuration:commons-configuration:1.8 (*)
|    |    |    +--- com.sun.jersey:jersey-servlet:1.11 -> 1.18.1 (*)
|    |    |    +--- com.github.stephenc.high-scale-lib:high-scale-lib:1.1.2
|    |    |    +--- com.netflix.governator:governator:1.3.3
|    |    |    |    +--- com.google.inject.extensions:guice-grapher:3.0
|    |    |    |    |    +--- com.google.inject.extensions:guice-assistedinject:3.0
|    |    |    |    |    |    \--- com.google.inject:guice:3.0 (*)
|    |    |    |    |    +--- com.google.inject.extensions:guice-multibindings:3.0
|    |    |    |    |    |    \--- com.google.inject:guice:3.0 (*)
|    |    |    |    |    \--- com.google.inject:guice:3.0 (*)
|    |    |    |    +--- org.codehaus.jsr166-mirror:jsr166y:1.7.0
|    |    |    |    +--- com.google.guava:guava:14.0.1 -> 28.0-jre (*)
|    |    |    |    +--- com.google.inject:guice:3.0 (*)
|    |    |    |    +--- org.apache.xbean:xbean-finder:3.11.1
|    |    |    |    |    +--- org.apache.xbean:xbean-bundleutils:3.11.1
|    |    |    |    |    |    \--- org.slf4j:slf4j-api:1.5.11 -> 1.7.7
|    |    |    |    |    \--- org.slf4j:slf4j-api:1.5.11 -> 1.7.7
|    |    |    |    +--- asm:asm-all:3.2
|    |    |    |    +--- com.google.inject.extensions:guice-multibindings:3.0 (*)
|    |    |    |    +--- org.slf4j:slf4j-api:1.6.3 -> 1.7.7
|    |    |    |    +--- org.apache.xbean:xbean-bundleutils:3.11.1 (*)
|    |    |    |    +--- javax.inject:javax.inject:1
|    |    |    |    +--- com.netflix.archaius:archaius-core:0.5.12 -> 0.6.3 (*)
|    |    |    |    \--- org.hibernate:hibernate-validator:4.1.0.Final
|    |    |    |         +--- javax.validation:validation-api:1.0.0.GA
|    |    |    |         \--- org.slf4j:slf4j-api:1.5.6 -> 1.7.7
|    |    |    +--- org.codehaus.jackson:jackson-mapper-asl:1.9.11 (*)
|    |    |    +--- com.sun.jersey.contribs:jersey-guice:1.9.1 -> 1.18.1 (*)
|    |    |    +--- com.sun.jersey:jersey-server:1.11 -> 1.18.1 (*)
|    |    |    +--- org.codehaus.jettison:jettison:1.1 (*)
|    |    |    +--- com.google.inject.extensions:guice-servlet:3.0 (*)
|    |    |    +--- com.google.code.findbugs:annotations:2.0.0
|    |    |    \--- commons-io:commons-io:1.4
|    |    \--- com.sun.jersey:jersey-core:1.18.1
|    +--- org.apache.httpcomponents:httpclient:4.2.1
|    |    +--- org.apache.httpcomponents:httpcore:4.2.1
|    |    +--- commons-logging:commons-logging:1.1.1
|    |    \--- commons-codec:commons-codec:1.6
|    \--- com.google.code.gson:gson:2.1
+--- com.netflix.karyon:karyon2-jersey-blocking:2.7.1
|    +--- org.slf4j:slf4j-api:1.7.6 -> 1.7.7
|    +--- com.netflix.karyon:karyon2-governator:2.7.1
|    |    +--- org.slf4j:slf4j-api:1.7.6 -> 1.7.7
|    |    +--- com.netflix.governator:governator:1.3.3 (*)
|    |    \--- com.netflix.karyon:karyon2-core:2.7.1
|    |         +--- org.slf4j:slf4j-api:1.7.6 -> 1.7.7
|    |         \--- io.reactivex:rxnetty-contexts:0.4.7
|    |              +--- io.reactivex:rxjava:1.0.8
|    |              \--- io.reactivex:rxnetty:0.4.7
|    |                   +--- io.reactivex:rxjava:1.0.8
|    |                   +--- io.netty:netty-codec-http:4.0.25.Final
|    |                   |    +--- io.netty:netty-codec:4.0.25.Final
|    |                   |    |    \--- io.netty:netty-transport:4.0.25.Final
|    |                   |    |         \--- io.netty:netty-buffer:4.0.25.Final
|    |                   |    |              \--- io.netty:netty-common:4.0.25.Final
|    |                   |    \--- io.netty:netty-handler:4.0.25.Final
|    |                   |         +--- io.netty:netty-buffer:4.0.25.Final (*)
|    |                   |         +--- io.netty:netty-transport:4.0.25.Final (*)
|    |                   |         \--- io.netty:netty-codec:4.0.25.Final (*)
|    |                   +--- io.netty:netty-transport-native-epoll:4.0.25.Final
|    |                   |    +--- io.netty:netty-common:4.0.25.Final
|    |                   |    +--- io.netty:netty-buffer:4.0.25.Final (*)
|    |                   |    \--- io.netty:netty-transport:4.0.25.Final (*)
|    |                   \--- org.slf4j:slf4j-api:1.7.6 -> 1.7.7
|    +--- com.google.guava:guava:14.0.1 -> 28.0-jre (*)
|    +--- com.netflix.archaius:archaius-core:0.6.3 (*)
|    +--- com.sun.jersey:jersey-core:1.18.1
|    +--- com.sun.jersey.contribs:jersey-guice:1.18.1 (*)
|    +--- com.sun.jersey:jersey-servlet:1.18.1 (*)
|    \--- com.sun.jersey:jersey-server:1.18.1 (*)
+--- com.netflix.karyon:karyon2-archaius:2.7.1
|    +--- org.slf4j:slf4j-api:1.7.6 -> 1.7.7
|    +--- com.netflix.karyon:karyon2-governator:2.7.1 (*)
|    \--- com.netflix.archaius:archaius-core:0.6.3 (*)
\--- com.google.guava:guava:28.0-jre (*)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题