1
votes

Hi I'm having 2 projects with files as below:

project1
  \- build.gradle

project2
  \- build.gradle
  \- build.properties

project1: build.gradle

apply from: '/home/project2/build.gradle     
test/test2/build.gradle'

task test1 {
  println "Running task test 1"
}

test1.dependsOn test2

project2: build.gradle

task test2 {
  println "Running task test 2"
  Properties props = new Properties()
  props.load(new FileInputStream("build.properties"))
}

When i execute test1 task from project1, i'm getting following error:

Running task test 2

FAILURE: Build failed with an exception.

  • Where: Script '/home/project2/build.gradle' line: 4

  • What went wrong: A problem occurred evaluating script. build.properties (No such file or directory)

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

BUILD FAILED

Total time: 5.779 secs

As gradle is working with relative path, it tries to search for build.properties file in project1 directory which is actually present in project2 directory. I can also move that file into project1 directory but that is what i don't wants to do.

I can also use absolute path in build.gradle but is that only solution?

I wants to run project2:test2 task from project1:test1 task without much modification in project2:build.gradle as i'm referring multiple file in this file.

1
Are you by chance using these build.properties to configure your build? If so, you might consider using gradle.properties instead - docs.gradle.org/current/userguide/build_environment.htmlEric Wendelin
Thanks Eric, But we need build.properties rather than gradle.properties file (Requirement).Satish Lakhani

1 Answers

0
votes

You may try not to apply the full build script, as you do now, but make a task from project1 depending on task from project2, as:

test1.dependsOn ':project2:test2'

But for that, you need to have all this project be subprojects of the same root project and have a settings.gradle file in the root project, defining this subprojects. You can read about it in the official documentation.

Otherwise you need to move the properties file into project1 directory or use relative or absolute path, since applying is just extends your current build script with some additional behaviour, but not make it so, as it was separate project.