我无法使用Gradle,Dropwizard和IntelliJ调试JavaEE应用程序

时间:2018-09-04 09:12:10

标签: java gradle intellij-idea dropwizard

我有一个使用Gradle的JavaEE应用程序,我在官方文档(针对Maven)和Gradle的另一本指南之后添加了Dropwizard:

https://www.dropwizard.io/1.3.5/docs/getting-started.html https://karollotkowski.wordpress.com/2015/10/13/run-dropwizard-with-gradle/

该应用程序配置良好,可与Gradle和Dropwizard一起运行,但是我想使用断点调试该应用程序,但我无法做到这一点。我遵循此指南:

https://medium.com/grandcentrix/how-to-debug-gradle-plugins-with-intellij-eef2ef681a7b

看起来不错,因为当我运行命令时:

  

sudo ./gradlew运行-Dorg.gradle.debug = true --no-daemon

Gradle等待我确实在IntelliJ中单击了远程调试配置(由我创建了它)来运行该应用程序,因此应该没问题。但是,它永远不会在我的断点处停下来(看起来它忽略了它们)。任何想法?我分享了我认为重要的文件:

build.gradle:

apply plugin: 'com.google.protobuf'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'

project.ext {
    dropwizardVersion = '1.3.0'
    configPath = "$rootProject.projectDir/config/"
}

//
// Loads of repositories and dependencies including dropwizard
//

protobuf {
// Configure the protoc executable
    protoc {
        // Download from repositories
        artifact = 'com.google.protobuf:protoc:3.0.0'
    }

    generateProtoTasks.generatedFilesBaseDir = 'generated'

    generateProtoTasks {
        // all() returns the collection of all protoc tasks
        all().each { task ->
            // Here you can configure the task
        }

        // In addition to all(), you may get the task collection by various
        // criteria:

        // (Java only) returns tasks for a sourceSet
        ofSourceSet('main')

    }
}

mainClassName = "com.company.MyApplication"

run {
    args 'server', configPath + ‘myapplication_config.yml'
}

shadowJar {
    mergeServiceFiles()
    exclude 'META-INF/*.DSA'
    exclude 'META-INF/*.RSA'
}

jar {
    manifest {
        attributes 'Main-Class': mainClassName
    }
}

build.dependsOn shadowJar

MyApplicationApplication(Dropwizard应用程序):

public class MyApplicationApplication extends Application<MyApplicationConfiguration> {

    public static void main(String[] args) throws Exception {

        new MyApplicationApplication().run(args);
    }

    @Override
    public void run(MyApplicationConfiguration configuration,
                    Environment environment) {

        environment.jersey().register(new RESTUserBilling());

    }
}

MyApplicationConfiguration(Dropwizard配置):

public class MyApplicationConfiguration extends Configuration {

}

myapplication_config.yml:

# Logging settings.
logging:

  # The default level of all loggers. Can be OFF, ERROR, WARN, INFO, DEBUG, TRACE, or ALL.
  level: ERROR, DEBUG

  # Logger-specific levels.
  loggers:

    # Sets the level for 'com.example.app' to DEBUG.
    com.company: DEBUG

  appenders:
  - type: console
  - type: file
    threshold: INFO
    logFormat: "%-6level [%d{HH:mm:ss.SSS}] [%t] %logger{5} - %X{code} %msg %n"
    currentLogFilename: /var/log/dropwizard/myapplication.log
    archivedLogFilenamePattern: /var/log/dropwizard/myapplication-%d{yyyy-MM-dd}-%i.log.gz
    archivedFileCount: 7
    timeZone: UTC
    maxFileSize: 10MB

server:
  applicationContextPath: /myapplication
  adminConnectors:
  -
    port: 8091
    type: http
  applicationConnectors:
  -
    port: 80
    type: http
IntelliJ IntelliJ 2018.2.1(Community Edition)中的

远程配置

enter image description here

  

2.12级

     

Java版本1.8.0_181

     

Dropwizard版本1.3.0

1 个答案:

答案 0 :(得分:1)

通过使用-Dorg.gradle.debug=true就像在那篇文章中那样,您正在调试Gradle的进程,而不是正在处理的应用程序。 Gradle在另一个过程中运行您的应用程序。您应该尝试gradle --debug-jvm run。详细了解该herehere

认真地更新Gradle。 2.12太旧了。使用wrapper

如果2.12无法理解--debug-jvm(可能是这种情况),那么只需找到一种方法即可向您的应用运行的JVM提供这样的字符串-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005(而不是Gradle本身)