$ mkdir creating-multi-project-builds
$ cd creating-multi-project-builds
$ gradle init
- configure repository for
allprojects
- set the version for each of the modules via the
subproject
block
$ mkdir greeting-library
- Create a build script in the greeting-library
- add
greeting-library
to root project - ---write code & test case --
mkdir greeter
- Create a build script in the
greeter
- add
greeter
to root project - Use
mainClassName
to set the entry point. (The assigned class must have a standard main method) - ---write code (use
greeting-library
functionality in it )& test case -- as pof now compile error will be there as dependency not define- link the artifacts of one subproject
greeter
to the dependencies of another sub-projectgreeting-library
...- Use the
project(NAME)
syntax to add the artifacts of one subproject to the dependencies of another subproject. - Run the build again, which should now succeed. (
gradlew :greeter:test
)
- Use the
It is possible to run any task in any sub-project from the top (or any other subproject), by using the format :SUBPROJECT:TASK
as the task name.
1.Start by adding the Asciidoctor
plugin to a plugins
block to the top of the root project build script.but don't apply.
...
- The use of
apply false
adds the plugin to the overall project, but does not add it to the root project.
mkdir docs
- Create a build script in the
docs
...- Apply the
Asciidoctor
plugin to this subproject. This technique lets you selectively apply plugins to sub-projects while defining all of the plugins in the root project. - Tell the plugin to look for a document called
greeter.adoc
in the default source foldersrc/docs/asciidoc
- Adds
asciidoctor
task into the build lifecycle so that if build is executed for the top-level project, then documentation will be built as well.
- Apply the
- add
docs
to root project - Add a document called
greeter.adoc
in the Asciidoctor source folder,src/docs/asciidoc
...- The documentation artifact will appear in
docs/build/asciidoc/html5
.
- The documentation artifact will appear in
- Add the generated documentation to the distribution.
...
- distZip
- distTar
- Use
project(:NAME)
to reference another project and its tasks. - If you unpack one of the archives (greeter-1.0.zip or greeter-1.0.tar in the greeter/build/distributions directory) you will see the documentation included in the html5 folder.
- At this point you might have noticed that you have common script code in both greeting-library and greeter sub-projects build scripts.
- A key feature of Gradle is the ability to place such common build script code in the root project.
gradlew clean build