Creating a multi java project using Gradle

I tear my hair off of it. I canceled my scripts directly to the code presented on the pages of the Gradle tutorial, since I think that I am either doing something fundamentally wrong or misunderstood how it is supposed that a multi-project application should be structured using gradle.

I have three java projects in eclipse, with all three containing a build.gradle script and only one containing settings.gradle script. The structure is as follows:

Scripts -- build.gradle -- settings.gradle Database -- build.gradle Services -- build.gradle 

I am trying to build a "Database" and "Services" project using the script construct in the "Scripts" project. To create a project tree, I have the following code in settings.gradle:

 include 'Services', 'Database' project (':Services').projectDir = new File(settingsDir, "../Services") project (':Database').projectDir = new File(settingsDir, "../Database") 

By replicating the code in a multi-project tutorial (gradle docs), I try to get each build script to print some text so that everything is set up correctly. My ultimate goal is to build dependencies correctly when the "eclipseClasspath" runs so that all projects compile correctly in eclipse. However, the text does not print as I expected!

Below is what is contained in the three build scripts:

Build.gradle scripts

 allprojects { task hello << { task -> println "I'm $task.project.name" } } subprojects { hello << {println "- I depend on Scripts"} } 

Build.gradle database

 hello.doLast { println "- I'm inside database" } 

Build.gradle services

 hello.doLast { println "- I'm inside services" } 

In the Scripts project, when I run gradle -q hello, I get the following results:

 I'm Scripts I'm AnprDatabase - I depend on Scripts I'm Database - I depend on Scripts 

Why doesn't the text “I'm inside the database” and “I'm inside the services” appear? I am a little puzzled by this. I can only guess that this has something to do with my project structure. Can anyone confirm this? If not, what is the problem? As already mentioned, I canceled my scripts with this simple example, since I could not get the dependencies to run a build script in every project using the same structure.

Thanks so much for any help offered.

+7
source share
1 answer

I managed to find out why it does not work. It was a stupid mistake on my part. The project "Database" and "Services" was not in the same directory as my project "Scripts". I checked these projects in a git repository that copies local directories from my Eclipse workspace and into a local git repository. I did not check out the Scripts project in my git repository, so it was still in my Eclipse workspace. It seems very obvious now why this did not work! Checking my project "Scripts" and changing the path to other projects in the settings .gradle fixed the problem.

Interestingly, instead of throwing a FileNotFoundException or something similar, Gradle will create an empty project if it cannot find the one that is defined. It was something that I did not appreciate. At first, I thought this was a weird behavior, but I suppose it gives the user the ability to create their projects on the fly during script execution. Not sure I like it!

So, always make sure that you go to the correct directory in your settings when you turn on projects! Otherwise, you may fall like me.

+4
source

All Articles