Declared dependency ignored at buidSrc/build.gradle


(Kauê Carbonari) #1

I am creating a custom task that needs to execute a rest service.

I declare jersey as dependency in buildSrc/build.gradle but is being ignore at compilation causing java compile error on task class:

Task Class:

import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.TaskAction;
  import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
    public class PackageBuilder extends DefaultTask {
      @Input
    public String userid;
      @Input
    public String source;
      @Input
    public String name;
      @Input
    public String version;
      @Input
    public String summary;
      @Input
    public String packageDescription;
      @Input
    public String url;
      @Input
    public String changelog;
        @TaskAction
    void start() {
          Client client = ClientBuilder.newClient();
    }
  }

build.gradle:

apply plugin: "groovy"
apply plugin: "java"
  repositories {
    mavenCentral()
    mavenLocal()
}
  dependencies {
      compile gradleApi()
    compile localGroovy()
      compile 'org.glassfish.jersey.core:jersey-client:2.4.1'
  }

Error Message:

:buildSrc:compileJava buildSrc/src/main/java/br/com/project/gradle/PackageBuilder.java:8: error: package javax.ws.rs.client does not exist import javax.ws.rs.client.Client;

^ buildSrc/src/main/java/br/com/project/gradle/PackageBuilder.java:9: error: package javax.ws.rs.client does not exist import javax.ws.rs.client.ClientBuilder;

^ buildSrc/src/main/java/br/com/project/gradle/PackageBuilder.java:42: error: cannot find symbol

Client client = ClientBuilder.newClient();

^

symbol:

class Client

location: class PackageBuilder buildSrc/src/main/java/br/com/project/gradle/PackageBuilder.java:42: error: cannot find symbol

Client client = ClientBuilder.newClient();

^

symbol:

variable ClientBuilder

location: class PackageBuilder 4 errors :buildSrc:compileJava FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ‘:compileJava’. > Compilation failed; see the compiler error output for details.

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

I apreciate any thoughts. Tks in advance.


(Kauê Carbonari) #2

A guy from work figure it out.

We tried to change build.gradle file names from all sub projects for something like “subProjectsName.gradle” in settings.gradle.

The buildSrc sub project was included as a module in settings.gradle so the IDE could import it. We assumed that renaming buildSrc/build.gradle to buildSrc/buildSrc.gradle was mandatory but instead gradle always assume that buildSrc has a build.gradle file no matter what.

I don not know if it is an issue but at least it is really confusing. I still would like ask: why buildSrc/build.gradle name can not be changed?

Tks in advanced


(Peter Niederwieser) #3

‘buildSrc’ is a separate build. You can change the ‘buildSrc/build.gradle’ name by adding an appropriate ‘buildSrc/settings.gradle’.