Skip to content

Instantly share code, notes, and snippets.

@sustacek
Last active November 4, 2020 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sustacek/322318eb01fc9c5014efc0f7622b6062 to your computer and use it in GitHub Desktop.
Save sustacek/322318eb01fc9c5014efc0f7622b6062 to your computer and use it in GitHub Desktop.
Liferay Workspace - Tomcat version check between configs and used bundle
// [root]/build.gradle
// A sanity check in case the Tomcat version inside the bundle changes and we miss it
[
(initBundle): gradle.liferayWorkspace.homeDir,
(distBundle): file("${buildDir}/dist")
].each {Task task, File destDir ->
task.configure {
doLast {
println "Checking Tomcat files in " + destDir
def tomcatDirNameMatchingBundle = "tomcat-" + gradle.liferayWorkspace.appServerTomcatVersion
def offendingTomcatFiles =
fileTree(destDir)
.include("tomcat-*/**")
.exclude("${tomcatDirNameMatchingBundle}/**")
if (!offendingTomcatFiles.isEmpty()) {
throw new GradleException(
"Some of the files copied from '${relativePath(gradle.liferayWorkspace.configsDir)}' have a wrong " +
"Tomcat version. Make sure to place Tomcat files only inside '${tomcatDirNameMatchingBundle}'" +
" to be matching the Tomcat dir in the configured bundle.\n" +
offendingTomcatFiles.collect { " * ${it.absolutePath - destDir.absolutePath}" }.join("\n"))
}
}
}
}
@sustacek
Copy link
Author

sustacek commented Nov 4, 2020

If you forget to rename your tomcat dir in {{configs}}, the build will fail, listing the files you need to move:

[master ✗] $ grw initBundle
Locating Gradle Wrapper... found (/opt/devel/liferay/github/f-esignature/gradlew)

> Task :initBundle
Checking Tomcat files in /opt/devel/liferay/github/f-esignature/bundles

> Task :initBundle FAILED

FAILURE: Build failed with an exception.

* Where:
Build file '/opt/devel/liferay/github/f-esignature/build.gradle' line: 91

* What went wrong:
Execution failed for task ':initBundle'.
> Some of the files copied from 'configs' have a wrong Tomcat version. Make sure to place Tomcat files only inside 'tomcat-9.0.17' to be matching the Tomcat dir in the configured bundle.
    * /tomcat-9.0.33/a.txt

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 11s
3 actionable tasks: 3 executed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment