In my plugin I am tapping into BuildManagerListener to generate spring banner during build time. In the banner caption I would like to print the JDK version, Maven/Gradle Version and SpringBoot version.
I am able to obtain the SDK type and version but I am not sure how to determine build tool type(Maven/Gradle), version and springboot version.
Currently I am overriding beforeBuildProcessStarted method.
Any help is appreciated.
prasanta.k.bhuyan:
SpringBoot version
The version information can be obtained using OrderEnumerator and Library.getMavenCoordinates()
Something like this:
OrderEnumerator.orderEntries(project).recursively()
.forEachLibrary { library: Library? ->
val coordinates = JavaLibraryUtil.getMavenCoordinates(library!!)
if (coordinates != null) {
}
}
You can also check if there are Spring Boot dependencies via JavaLibraryUtil.hasLibraryJar for project and modules.
Thanks. Worked for me. Here’s a full example in case anyone needs.
private String getSpringBootVersion(@NotNull Project project) {
final AtomicReference<String> springBootVersion = new AtomicReference<>();
OrderEnumerator orderEnumerator = OrderEnumerator.orderEntries(project).librariesOnly();
orderEnumerator.forEachLibrary(library -> {
val coordinate = JavaLibraryUtil.getMavenCoordinates(library);
if (coordinate != null &&
SPRING_BOOT_GROUP_ID.equalsIgnoreCase(coordinate.getGroupId()) &&
SPRING_BOOT_ARTIFACT_ID.equalsIgnoreCase(coordinate.getArtifactId())) {
springBootVersion.set(coordinate.getVersion());
return false;
}
return true;
});
return springBootVersion.get();
}
Prasanta_Bhuyan:
Maven/Gradle Version
@yuriy.artamonov Is there a way to obtain build tool version?