1
votes

I have the following project-structure:

Root project 'rmi-tutorial'
+--- Project ':client'
+--- Project ':lib'
\--- Project ':server'

When I execute the run task of the root-project I will get the following error:

Execution failed for task ':lib:run'.

How can I exclude the :lib subproject from being run? I don't want to exclude the subproject completly and I also don't want to exclude it manually via command line parameters. When I execute the "build" task of the root-project it should build lib. When i execute "run" of the root-project it should run only the sub-projects "server" and "client".

Moreover server should be run before client. Any idea how to accomplish this without starting it manually in the correct order?

I know that I can do:

gradlew.bat build
gradlew.bat server:run
gradlew.bat client:run

but that is not what i want to do. I would prefer something like this:

gradlew.bat run
1

1 Answers

2
votes

The run task is created by the Application Plugin, but the plugin is not designed for library projects. You could only apply the Distribution Plugin (apply plugin: 'distribution') or the Java Plugin (apply plugin: 'java'), which are both implicitly applied by the Application Plugin. This way, your lib subproject would not contain a run task and only the run tasks of the subprojects client and server would be executed.

Otherwise, if you really need the Application Plugin, you could exclude the run task via the StartParameter object in your settings.gradle file:

[...] // include subprojects

startParameter.excludedTaskNames << ':lib:run'

This task will be excluded from each build.

To manage the order of tasks, you can use the methods shouldRunAfter and mustRunAfter (just like dependsOn):

tasks.getByPath(':client:run').mustRunAfter(tasks.getByPath(':server:run'))