@@ -6,6 +6,7 @@ import com.sun.jdi.*
66import kotlinx.coroutines.CoroutineScope
77import kotlinx.coroutines.Dispatchers
88import kotlinx.coroutines.launch
9+ import org.gradle.tooling.BuildCancelledException
910import org.gradle.tooling.BuildLauncher
1011import org.gradle.tooling.GradleConnector
1112import org.gradle.tooling.events.ProgressListener
@@ -29,6 +30,7 @@ class GradleJob{
2930 NONE ,
3031 BUILDING ,
3132 RUNNING ,
33+ ERROR ,
3234 DONE
3335 }
3436
@@ -64,7 +66,31 @@ class GradleJob{
6466 run ()
6567 }
6668 }catch (e: Exception ){
67- Messages .log(" Error while running: ${e.message} ${e.cause?.message} " )
69+ val causesList = mutableListOf<Throwable >()
70+ var cause: Throwable ? = e
71+ while (cause != null && cause.cause != cause) {
72+ causesList.add(cause)
73+ cause = cause.cause
74+ }
75+
76+ val errors = causesList.joinToString(" \n " ) { it.message ? : " Unknown error" }
77+
78+ val skip = listOf (BuildCancelledException ::class )
79+
80+ if (skip.any { it.isInstance(e) }) {
81+ Messages .log(" Gradle job error: $errors " )
82+ return @launch
83+ }
84+
85+ if (state.value != State .BUILDING ){
86+ Messages .log(" Gradle job error: $errors " )
87+ return @launch
88+ }
89+
90+ // An error occurred during the build process
91+
92+ System .err.println (errors)
93+ service?.editor?.statusError(cause?.message)
6894 }finally {
6995 state.value = State .DONE
7096 vm.value = null
@@ -94,30 +120,40 @@ class GradleJob{
94120 }
95121
96122 when (event.descriptor.name){
97- " :jar" -> {
98- state.value = State .NONE
99- Messages .log(" Jar finished" )
100- }
101123 " :run" -> {
102- state.value = State .NONE
124+ state.value = State .DONE
103125 service?.editor?.toolbar?.deactivateRun()
104126 service?.editor?.toolbar?.deactivateStop()
105127 }
106128 }
107129 }
108130 if (event is DefaultSingleProblemEvent ) {
109- /*
110- We have 6 lines to display the error in the editor.
111- */
112131
113- if (event.definition.severity == Severity . ADVICE ) return @ProgressListener
132+
114133 problems.add(event)
115134
135+ val skip = listOf (
136+ " mutating-the-dependencies-of-configuration-implementation-after-it-has-been-resolved-or-consumed-this-behavior-has-been-deprecated" ,
137+ " mutating-the-dependencies-of-configuration-runtimeonly-after-it-has-been-resolved-or-consumed-this-behavior-has-been-deprecated"
138+ )
139+ if (skip.any { event.definition.id.name.contains(it) }) {
140+ Messages .log(event.toString())
141+ return @ProgressListener
142+ }
143+
144+ if (event.definition.severity == Severity .ADVICE ) {
145+ Messages .log(event.toString())
146+ return @ProgressListener
147+ }
116148 // TODO: Show the error on the location if it is available
149+ /*
150+ We have 6 lines to display the error in the editor.
151+ */
117152
118153 val error = event.definition.id.displayName
119154 service?.editor?.statusError(error)
120155 System .err.println (" Problem: $error " )
156+ state.value = State .ERROR
121157
122158 val message = """
123159 Context: ${event.contextualLabel.contextualLabel}
0 commit comments