|
| 1 | +import org.apache.tools.ant.taskdefs.condition.* |
| 2 | +import org.gradle.internal.logging.text.* |
| 3 | +import org.apereo.cas.metadata.* |
| 4 | +import java.nio.file.* |
| 5 | +import org.gradle.internal.logging.text.* |
| 6 | +import static org.gradle.internal.logging.text.StyledTextOutput.Style |
| 7 | + |
| 8 | +buildscript { |
| 9 | + repositories { |
| 10 | + if (project.privateRepoUrl) { |
| 11 | + maven { |
| 12 | + url project.privateRepoUrl |
| 13 | + credentials { |
| 14 | + username = project.privateRepoUsername |
| 15 | + password = System.env.PRIVATE_REPO_TOKEN |
| 16 | + } |
| 17 | + } |
| 18 | + } |
| 19 | + mavenLocal() |
| 20 | + mavenCentral() |
| 21 | + gradlePluginPortal() |
| 22 | + maven { |
| 23 | + url 'https://oss.sonatype.org/content/repositories/snapshots' |
| 24 | + mavenContent { snapshotsOnly() } |
| 25 | + } |
| 26 | + maven { |
| 27 | + url "https://repo.spring.io/milestone" |
| 28 | + mavenContent { releasesOnly() } |
| 29 | + } |
| 30 | + } |
| 31 | + dependencies { |
| 32 | + classpath "org.springframework.boot:spring-boot-gradle-plugin:${project.springBootVersion}" |
| 33 | + classpath "io.freefair.gradle:maven-plugin:${project.gradleFreeFairPluginVersion}" |
| 34 | + classpath "io.freefair.gradle:lombok-plugin:${project.gradleFreeFairPluginVersion}" |
| 35 | + classpath "io.spring.gradle:dependency-management-plugin:${project.gradleDependencyManagementPluginVersion}" |
| 36 | + classpath "com.google.cloud.tools:jib-gradle-plugin:${project.jibVersion}" |
| 37 | + classpath "com.bmuschko:gradle-docker-plugin:${project.gradleDockerPluginVersion}" |
| 38 | + |
| 39 | + classpath "de.undercouch:gradle-download-task:${project.gradleDownloadTaskVersion}" |
| 40 | + classpath "org.apereo.cas:cas-server-core-api-configuration-model:${project.'cas.version'}" |
| 41 | + classpath "org.apereo.cas:cas-server-core-configuration-metadata-repository:${project.'cas.version'}" |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +repositories { |
| 46 | + if (project.privateRepoUrl) { |
| 47 | + maven { |
| 48 | + url project.privateRepoUrl |
| 49 | + credentials { |
| 50 | + username = project.privateRepoUsername |
| 51 | + password = System.env.PRIVATE_REPO_TOKEN |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | + mavenLocal() |
| 56 | + mavenCentral() |
| 57 | + maven { url 'https://oss.sonatype.org/content/repositories/releases' } |
| 58 | + maven { |
| 59 | + url 'https://oss.sonatype.org/content/repositories/snapshots' |
| 60 | + mavenContent { snapshotsOnly() } |
| 61 | + } |
| 62 | + maven { |
| 63 | + url "https://repository.apache.org/content/repositories/snapshots" |
| 64 | + mavenContent { snapshotsOnly() } |
| 65 | + } |
| 66 | + maven { |
| 67 | + url 'https://build.shibboleth.net/nexus/content/repositories/releases/' |
| 68 | + mavenContent { releasesOnly() } |
| 69 | + } |
| 70 | + maven { |
| 71 | + url "https://build.shibboleth.net/nexus/content/repositories/snapshots" |
| 72 | + mavenContent { snapshotsOnly() } |
| 73 | + } |
| 74 | + maven { |
| 75 | + url "https://repo.spring.io/milestone" |
| 76 | + mavenContent { releasesOnly() } |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | + |
| 81 | +apply plugin: "io.freefair.war-overlay" |
| 82 | +apply plugin: "war" |
| 83 | + |
| 84 | +apply plugin: "org.springframework.boot" |
| 85 | +apply plugin: "io.freefair.lombok" |
| 86 | + |
| 87 | + |
| 88 | +apply from: rootProject.file("gradle/springboot.gradle") |
| 89 | +apply plugin: "com.google.cloud.tools.jib" |
| 90 | +apply plugin: "com.bmuschko.docker-remote-api" |
| 91 | +apply from: rootProject.file("gradle/tasks.gradle") |
| 92 | + |
| 93 | + |
| 94 | +configurations { |
| 95 | + all { |
| 96 | + resolutionStrategy { |
| 97 | + cacheChangingModulesFor 0, "seconds" |
| 98 | + cacheDynamicVersionsFor 0, "seconds" |
| 99 | + preferProjectModules() |
| 100 | + def failIfConflict = project.hasProperty("failOnVersionConflict") && Boolean.valueOf(project.getProperty("failOnVersionConflict")) |
| 101 | + if (failIfConflict) { |
| 102 | + failOnVersionConflict() |
| 103 | + } |
| 104 | + |
| 105 | + if (project.hasProperty("tomcatVersion")) { |
| 106 | + eachDependency { DependencyResolveDetails dependency -> |
| 107 | + def requested = dependency.requested |
| 108 | + if (requested.group.startsWith("org.apache.tomcat") && requested.name != "jakartaee-migration") { |
| 109 | + dependency.useVersion("${tomcatVersion}") |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | + } |
| 114 | + exclude(group: "cglib", module: "cglib") |
| 115 | + exclude(group: "cglib", module: "cglib-full") |
| 116 | + exclude(group: "org.slf4j", module: "slf4j-log4j12") |
| 117 | + exclude(group: "org.slf4j", module: "slf4j-simple") |
| 118 | + exclude(group: "org.slf4j", module: "jcl-over-slf4j") |
| 119 | + exclude(group: "org.apache.logging.log4j", module: "log4j-to-slf4j") |
| 120 | + } |
| 121 | +} |
| 122 | + |
| 123 | +war { |
| 124 | + entryCompression = ZipEntryCompression.STORED |
| 125 | + enabled = false |
| 126 | +} |
| 127 | + |
| 128 | +java { |
| 129 | + toolchain { |
| 130 | + languageVersion = JavaLanguageVersion.of(project.targetCompatibility) |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +bootBuildImage { |
| 135 | + imageName = "${project.'containerImageOrg'}/${project.'containerImageName'}:${project.version}" |
| 136 | +} |
| 137 | + |
| 138 | + |
| 139 | +['jibDockerBuild', 'jibBuildTar', 'jib'].each { taskName -> |
| 140 | + if (gradle.gradleVersion >= "8.0") { |
| 141 | + getTasksByName(taskName, true).each(it -> { |
| 142 | + it.notCompatibleWithConfigurationCache("Jib is not compatible with configuration cache"); |
| 143 | + it.enabled = !gradle.startParameter.isConfigurationCacheRequested() |
| 144 | + }) |
| 145 | + } |
| 146 | +} |
| 147 | + |
| 148 | +def imagePlatforms = project.dockerImagePlatform.split(",") |
| 149 | +def dockerUsername = providers.systemProperty("dockerUsername").getOrNull() |
| 150 | +def dockerPassword = providers.systemProperty("dockerPassword").getOrNull() |
| 151 | +def imageTagPostFix = providers.systemProperty("dockerImageTagPostfix").getOrElse("") |
| 152 | + |
| 153 | +jib { |
| 154 | + if (gradle.gradleVersion >= "8.0" && gradle.startParameter.isConfigurationCacheRequested()) { |
| 155 | + def out = services.get(StyledTextOutputFactory).create("cas") |
| 156 | + out.withStyle(Style.Info).println("You are seeing this message because the Gradle configuration cache is turned on") |
| 157 | + out.withStyle(Style.Info).println("Running Jib tasks to produce Docker images will require the command-line option: --no-configuration-cache") |
| 158 | + out.withStyle(Style.Info).println("Jib does not support the Gradle configuration cache; Please see https://github.com/GoogleContainerTools/jib/issues/3132") |
| 159 | + out.withStyle(Style.Info).println("Jib tasks are disabled.") |
| 160 | + } |
| 161 | + from { |
| 162 | + image = project.baseDockerImage |
| 163 | + platforms { |
| 164 | + imagePlatforms.each { |
| 165 | + def given = it.split(":") |
| 166 | + platform { |
| 167 | + architecture = given[0] |
| 168 | + os = given[1] |
| 169 | + } |
| 170 | + } |
| 171 | + } |
| 172 | + } |
| 173 | + to { |
| 174 | + image = "${project.'containerImageOrg'}/${project.'containerImageName'}:${project.version}" |
| 175 | + /** |
| 176 | + ecr-login: Amazon Elastic Container Registry (ECR) |
| 177 | + gcr: Google Container Registry (GCR) |
| 178 | + osxkeychain: Docker Hub |
| 179 | + */ |
| 180 | + credHelper = "osxkeychain" |
| 181 | + if (dockerUsername != null && dockerPassword != null) { |
| 182 | + auth { |
| 183 | + username = "${dockerUsername}" |
| 184 | + password = "${dockerPassword}" |
| 185 | + } |
| 186 | + } |
| 187 | + tags = [project.version] |
| 188 | + } |
| 189 | + container { |
| 190 | + creationTime = "USE_CURRENT_TIMESTAMP" |
| 191 | + entrypoint = ['/docker/entrypoint.sh'] |
| 192 | + ports = ['80', '443', '8080', '8443', '8444', '8761', '8888', '5000'] |
| 193 | + labels = [version:project.version, name:project.name, group:project.group, org:project.containerImageOrg] |
| 194 | + workingDirectory = '/docker/cas/war' |
| 195 | + } |
| 196 | + extraDirectories { |
| 197 | + paths { |
| 198 | + path { |
| 199 | + from = file('src/main/jib') |
| 200 | + } |
| 201 | + path { |
| 202 | + from = file('etc/cas') |
| 203 | + into = '/etc/cas' |
| 204 | + } |
| 205 | + path { |
| 206 | + from = file("build/libs") |
| 207 | + into = "/docker/cas/war" |
| 208 | + } |
| 209 | + } |
| 210 | + permissions = [ |
| 211 | + '/docker/entrypoint.sh': '755' |
| 212 | + ] |
| 213 | + } |
| 214 | + allowInsecureRegistries = project.allowInsecureRegistries |
| 215 | +} |
| 216 | + |
| 217 | +import com.bmuschko.gradle.docker.tasks.image.* |
| 218 | +tasks.register("casBuildDockerImage", DockerBuildImage) { |
| 219 | + dependsOn("build") |
| 220 | + |
| 221 | + def imageTag = "${project.'cas.version'}" |
| 222 | + inputDir = project.projectDir |
| 223 | + images.add("apereo/cas:${imageTag}${imageTagPostFix}") |
| 224 | + images.add("apereo/cas:latest${imageTagPostFix}") |
| 225 | + if (dockerUsername != null && dockerPassword != null) { |
| 226 | + username = dockerUsername |
| 227 | + password = dockerPassword |
| 228 | + } |
| 229 | + doLast { |
| 230 | + def out = services.get(StyledTextOutputFactory).create("cas") |
| 231 | + out.withStyle(Style.Success).println("Built CAS images successfully.") |
| 232 | + } |
| 233 | +} |
| 234 | + |
| 235 | +tasks.register("casPushDockerImage", DockerPushImage) { |
| 236 | + dependsOn("casBuildDockerImage") |
| 237 | + |
| 238 | + def imageTag = "${project.'cas.version'}" |
| 239 | + images.add("apereo/cas:${imageTag}${imageTagPostFix}") |
| 240 | + images.add("apereo/cas:latest${imageTagPostFix}") |
| 241 | + |
| 242 | + if (dockerUsername != null && dockerPassword != null) { |
| 243 | + username = dockerUsername |
| 244 | + password = dockerPassword |
| 245 | + } |
| 246 | + doLast { |
| 247 | + def out = services.get(StyledTextOutputFactory).create("cas") |
| 248 | + out.withStyle(Style.Success).println("Pushed CAS images successfully.") |
| 249 | + } |
| 250 | +} |
| 251 | + |
| 252 | +dependencies { |
| 253 | + /** |
| 254 | + * Do NOT modify the lines below or else you will risk breaking dependency management. |
| 255 | + **/ |
| 256 | + implementation enforcedPlatform("org.apereo.cas:cas-server-support-bom:${project.'cas.version'}") |
| 257 | + implementation platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES) |
| 258 | + |
| 259 | + /** |
| 260 | + * Do NOT modify the lines below or else you will risk breaking the build. |
| 261 | + **/ |
| 262 | + implementation "org.apereo.cas:cas-server-core-api-configuration-model" |
| 263 | + implementation "org.apereo.cas:cas-server-webapp-init" |
| 264 | + |
| 265 | + if (project.hasProperty("appServer")) { |
| 266 | + implementation "org.apereo.cas:cas-server-webapp-init${project.appServer}" |
| 267 | + } |
| 268 | + |
| 269 | + developmentOnly "org.springframework.boot:spring-boot-devtools:${project.springBootVersion}" |
| 270 | + |
| 271 | + /** |
| 272 | + * CAS dependencies and modules may be listed here. |
| 273 | + * |
| 274 | + * There is no need to specify the version number for each dependency |
| 275 | + * since versions are all resolved and controlled by the dependency management |
| 276 | + * plugin via the CAS bom. |
| 277 | + **/ |
| 278 | + implementation "org.apereo.cas:cas-server-support-rest" |
| 279 | + |
| 280 | + |
| 281 | + testImplementation "org.springframework.boot:spring-boot-starter-test" |
| 282 | + |
| 283 | + |
| 284 | + implementation "org.apereo.cas:cas-server-core-services" |
| 285 | + implementation "org.apereo.cas:cas-server-support-json-service-registry" |
| 286 | +} |
0 commit comments