I have multiple java projects. these projects are creating jar,war and ear files using gradle. In each project I have used manifest file to maintain the meta data like version,date-time... Fro this I have included the manifest file creation logic in every build.gradle file.
manifest {
attributes(
'Bundle-Vendor' : "$BUNDLE_VENDOR",
'Build-Time': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"))
}
But in Gradle there is a feature call sharedManifest. I have defined the bellow two tasks in main project build.gradle script. But in the every jar and war file have the default MANIFEST.MF file created by Gradle.
ext.sharedManifest = manifest {
attributes(
'Bundle-Vendor' : "$BUNDLE_VENDOR",
'Build-Time': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
)
}
task fooJar(type: Jar) {
manifest = project.manifest {
from sharedManifest
}
}
task fooWar(type: War) {
manifest = project.manifest {
from sharedManifest
}
}
jar.manifest.writeTo("/MANIFEST.MF") war.manifest.writeTo("/MANIFEST.MF")
please can some one give the suggestion how to do this.
Hello , can i create multiple build. gradle for one project? Yes. You can have multiple build files in one project.
Let's create a project containing its subprojects and build the Gradle project. Co'sider the below project structure in which the root project name is Multi_project, and the subproject name is sub_project. Create a new root directory in which we want to create a multi-project. Use the below command to create a new directory:
The project API of the Gradle provides a method called project (); it takes the path as an argument and returns the object of the project for the current path. When a project build configures from a build script, then it is called cross-project configuration.
Gradle can handle smallest and largest projects easily. Small projects have a single build file and a source tree. It is very easy to digest and understand a project that has been split into smaller, inter-dependent modules. Gradle perfectly supports this scenario that is multi-project build.
A build.gradle file in the root or master directory. Child directories that have their own *.gradle build files (some multi-project builds may omit child project build scripts).
The easiest way to share manifest logic within a build is a configuration rule such as:
allprojects {
tasks.withType(Jar) { // includes War and Ear
manifest {
attributes ...
}
}
}
Also, there is another way to create a shared manifest:
Create a java.gradle file to keep configurations for Java subprojects and put inside:
ext.sharedManifest = manifest {
attributes(
.......
)
}
Then, in the root build.gradle apply this configuration for subprojects
subprojects {
apply from: "$rootDir/gradle/java.gradle"
.....
}
And there is possible to reuse this shared manifest and add extra attributes:
Subproject A:
jar {
manifest {
from sharedManifest
attributes(
'JavaFX-Application-Class': 'com.main.SomeClass',
.....
)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With