3939import org .gradle .api .file .FileVisitDetails ;
4040import org .gradle .api .file .FileVisitor ;
4141import org .gradle .api .logging .LogLevel ;
42+ import org .gradle .api .logging .LoggingManager ;
4243import org .gradle .api .tasks .Input ;
4344import org .gradle .api .tasks .OutputDirectory ;
4445import org .gradle .api .tasks .TaskAction ;
46+ import org .gradle .util .GradleVersion ;
4547
4648import com .google .common .base .Charsets ;
4749import com .google .common .base .Joiner ;
@@ -93,7 +95,7 @@ public void doStuff() throws IOException
9395 {
9496 out = out .replace (replacement .getKey (), (String ) replacement .getValue ());
9597 }
96-
98+
9799 // replace extra lines
98100 if (!extraLines .isEmpty ())
99101 {
@@ -125,12 +127,7 @@ public void doStuff() throws IOException
125127 col = col .plus (config );
126128 }
127129
128- AntBuilder ant = this .getAnt ();
129- // Remove errors on normal runs
130- LogLevel startLevel = getProject ().getGradle ().getStartParameter ().getLogLevel ();
131- if (startLevel .compareTo (LogLevel .LIFECYCLE ) >= 0 ) {
132- ant .setLifecycleLogLevel (AntMessagePriority .ERROR );
133- }
130+ AntBuilder ant = this .setupAnt ();
134131 // INVOKE!
135132 ant .invokeMethod ("javac" , ImmutableMap .builder ()
136133 .put ("srcDir" , resourceDir .getCanonicalPath ())
@@ -143,7 +140,7 @@ public void doStuff() throws IOException
143140 .put ("target" , "1.6" )
144141 .put ("debug" , "true" )
145142 .build ());
146-
143+
147144 // copy the sources too, for debugging through GradleStart
148145 getProject ().fileTree (resourceDir ).visit (new FileVisitor () {
149146
@@ -158,18 +155,42 @@ public void visitFile(FileVisitDetails arg0)
158155 {
159156 arg0 .copyTo (arg0 .getRelativePath ().getFile (compiled ));
160157 }
161-
158+
162159 });
163160 }
164161
165162 }
166163
164+ private AntBuilder setupAnt ()
165+ {
166+ AntBuilder ant = this .getAnt ();
167+ LogLevel startLevel = getProject ().getGradle ().getStartParameter ().getLogLevel ();
168+ if (startLevel .compareTo (LogLevel .LIFECYCLE ) >= 0 )
169+ {
170+ GradleVersion v2_14 = GradleVersion .version ("2.14" );
171+ if (GradleVersion .current ().compareTo (v2_14 ) >= 0 )
172+ {
173+ ant .setLifecycleLogLevel (AntMessagePriority .ERROR );
174+ }
175+ else
176+ {
177+ try {
178+ LoggingManager .class .getMethod ("setLevel" , LogLevel .class ).invoke (getLogging (), LogLevel .ERROR );
179+ } catch (Exception e ) {
180+ //Couldn't find it? We are on some weird version oh well.
181+ this .getLogger ().info ("Could not set log level:" , e );
182+ }
183+ }
184+ }
185+ return ant ;
186+ }
187+
167188 @ SuppressWarnings ("rawtypes" )
168189 private String resolveString (Object obj ) throws IOException
169190 {
170191 if (obj == null )
171192 return null ;
172-
193+
173194 if (obj instanceof Closure )
174195 return resolveString (((Closure ) obj ).call ());
175196 else if (obj instanceof File )
0 commit comments