Unable to resolve class ... in build.gradle script

(tulsoba) #1

I have a gradle multi project with a subproject A. In the subproject A I have a build.gradle file with the following task:

import com.samples.*;
  apply plugin: 'java'
apply plugin: 'maven'
  sourceSets {
 main {
  java {
   srcDir 'src'
  task myTask(dependsOn: "classes") << {
  MyClass m = new MyClass();

Where com.samples.MyClass is located in the source folder ‘src’. When I build this project with gradle clean install I get:

build file '....\build.gradle': 21: unable to resolve class MyClass
  @ line 21, column 15.
     MyClass m = new MyClass();

Why is MyClass not visible in the build script?

(Luke Daley) #2

The classes used by the build are entirely separate from the classes being built by the build. Groovy is a compiled language, which means the classes are needed before the script starts executing.

What are you trying to do?