title: How to import a class inside a gradle custom task?
body: <p>I'm trying to use <a href="http://willis7.github.io/blog/2013/gradle-output-to-log.html" rel="nofollow noreferrer">this</a> excerpt of code to intercept gradle logs into a file. I don't want to polute my <code>build.gradle</code>, therefore, I've created an <code>interceptor.gradle</code> to encapsulate this logic. It looks like that:</p>
  
  <p><strong><code>interceptor.gradle</code></strong></p>
  
  <pre><code>import org.gradle.logging.internal.*
  
  task intercept {
      def outputStream = new File("gradle.log")
          gradle.services.get(LoggingOutputInternal).addStandardOutputListener (new StandardOutputListener () {
                  void onOutput(CharSequence output) {
                      outputStream &lt;&lt; output
                  }
              }
          )
  }
  </code></pre>
  
  <p>And in my <code>build.gradle</code>, I've added:</p>
  
  <p><code>apply from: project.file('tooling/gradle/interceptor.gradle')</code></p>
  
  <p>The problem is: when I try to <code>./gradlew build</code> I get: </p>
  
  <pre><code>* What went wrong:
  A problem occurred evaluating script.
  &gt; Could not get unknown property 'LoggingOutputInternal' for task ':intercept' of type org.gradle.api.DefaultTask.
  </code></pre>
  
  <p>How can I isolate the code that intercepts gradle logs and save it into a file in a separate gradle script and make it get executed from main <code>build.gradle</code>?</p>