2016-03-08 29 views
0

調試一個空指針異常我有這個gradle.build常規文件:如何gradle.build

task BL_generate_parallel_warmup(type: JavaExec) { 
    if (project.hasProperty('serverversion')) { 
     args(serverversion) 
    } 
    if (project.hasProperty('input_flavor')) { 
     systemProperties['input_flavor'] = input_flavor 
     print "gradle input_flavor" + input_flavor 
    } 
    jvmArgs = ["-Xms1024m", "-Xmx1024m"] 
    classpath sourceSets.main.runtimeClasspath 
    dependsOn resources_cleaner_bl 
    systemProperties['isDummyRun'] = 'true' 
    main = "astar.BlParallelGenerator" 
} 

後,我就重構爲這樣:

def setSystemProperties() { 
    if (project.hasProperty('serverversion')) { 
     args(serverversion) 
    } 
    if (project.hasProperty('input_flavor')) { 
     systemProperties['input_flavor'] = input_flavor 
     print "gradle input_flavor" + input_flavor 
    } 
    jvmArgs = ["-Xms1024m", "-Xmx1024m"] 
    classpath sourceSets.main.runtimeClasspath 
} 



//warm up 

task BL_generate_parallel_warmup(type: JavaExec) { 
    setSystemProperties() 
    dependsOn resources_cleaner_bl 
    systemProperties['isDummyRun'] = 'true' 
    main = "astar.BlParallelGenerator" 
} 

我得到這個錯誤:

Error:(121, 0) A problem occurred evaluating root project 'MyProject'. 
<a href="openFile">Open File</a> 

更新

我改變解決了這個:

def setSystemProperties(project) { 
     if (project.hasProperty('serverversion')) { 
      args(serverversion) 
     } 
     if (project.hasProperty('input_flavor')) { 
      systemProperties['input_flavor'] = input_flavor 
      print "gradle input_flavor" + input_flavor 
     } 
     jvmArgs = ["-Xms1024m", "-Xmx1024m"] 
     classpath sourceSets.main.runtimeClasspath 
    } 



    //warm up 

    task BL_generate_parallel_warmup(type: JavaExec) { 
     setSystemProperties(project) 
     dependsOn resources_cleaner_bl 
     systemProperties['isDummyRun'] = 'true' 
     main = "astar.BlParallelGenerator" 
    } 

我怎麼能調試它在的IntelliJ?

我在調試中按下了運行,並向gradle build添加了一個斷點,但它不會在任何地方停止。

我試圖「編輯配置」是這樣的:

enter image description here ,但它並沒有在斷點處

回答

1

代碼停在搖籃用於調試的參考文檔可以在這裏找到:https://www.jetbrains.com/idea/help/create-run-debug-configuration-for-gradle-tasks.html

要爲Gradle任務創建調試配置,請右鍵單擊Gradle工具窗口中的任務,然後選擇Create。您將獲得有關如何配置調試配置的選項。

由於您使用的是類型爲JavaExec的任務,因此還有其他選項。 您可以在您的主類中放置斷點,並在IntelliJ中配置遠程調試會話。 enter image description here

由於圖像顯示時,我必須創建在你的JavaExec類型的任務在端口5005 聽然後遠程型調試配置,您將添加debug=true選項,如下所示:

task runApp(type: JavaExec){ 
    classpath file('c:/data/test') 
    main = 'TestMain' 
    debug = true 
} 

要進行調試,您需要在IntelliJ中的Gradle插件中單擊runApp任務,然後啓動Local_Port_5005遠程調試會話並讓任務在您的斷點停止。

enter image description here

+0

請看我PRINTSCREEN添加 –

+0

,我已經照你說的還是對BP –

+0

不會停止我已經更新了答案有更多的選擇,調試JavaExec類型的任務,這點我是能夠驗證並測試我自己(如圖所示)。 – pczeus