build.gradle 7.5 KB
Newer Older
1 2 3 4
buildscript {
    repositories {
        mavenLocal()
        jcenter()
5
        maven { url "https://repo.spring.io/libs-milestone" }
Misagh Moayyed's avatar
Misagh Moayyed committed
6
        maven { url "https://plugins.gradle.org/m2/" }
7 8
    }
    dependencies {
Misagh Moayyed's avatar
Misagh Moayyed committed
9
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${project.springBootVersion}"
Misagh Moayyed's avatar
Misagh Moayyed committed
10 11 12
        classpath "de.undercouch:gradle-download-task:3.4.3" // used to download CAS shell
        classpath "org.apache.ivy:ivy:2.4.0" // used to download CAS shell from snapshot repo
        classpath "gradle.plugin.com.google.cloud.tools:jib-gradle-plugin:0.10.0"
13 14 15 16 17 18 19
    }
}

repositories {
    mavenLocal()
    mavenCentral()
    jcenter()
Misagh Moayyed's avatar
Misagh Moayyed committed
20 21
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
    maven { url "https://build.shibboleth.net/nexus/content/repositories/releases/" }
22 23
    maven { url "https://repo.spring.io/milestone/" }
    maven { url "https://oss.jfrog.org/artifactory/oss-snapshot-local" }
24 25 26
}

apply from: "https://dl.bintray.com/scalding/generic/waroverlay.gradle"
Misagh Moayyed's avatar
Misagh Moayyed committed
27

Misagh Moayyed's avatar
Misagh Moayyed committed
28

29 30 31 32
apply plugin: "war"
apply plugin: "org.springframework.boot"
apply plugin: "eclipse"
apply plugin: "idea"
Misagh Moayyed's avatar
Misagh Moayyed committed
33 34 35 36 37 38 39 40 41
apply plugin: "de.undercouch.download"
apply plugin: "com.google.cloud.tools.jib"

def casServerVersion = project.'cas.version'
def casWebApplicationBinaryName = "cas.war"

configurations.all {
    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

eclipse {
    classpath {
       downloadSources = true
       downloadJavadoc = true
    }
}

idea {
    module {
        downloadJavadoc = true
        downloadSources = true
    }
}

war {
58
    includeWarJars = true
59
    entryCompression = ZipEntryCompression.STORED
60 61
}

62 63 64 65 66
springBoot {
    mainClassName = "org.apereo.cas.web.CasWebApplication"
}

bootWar {
Misagh Moayyed's avatar
Misagh Moayyed committed
67
	if (project.hasProperty("executable")) {
68 69 70
    	launchScript()
	}

Misagh Moayyed's avatar
Misagh Moayyed committed
71 72
	archiveName "${casWebApplicationBinaryName}"
    baseName "cas"
73 74 75 76 77 78 79 80 81

    excludeDevtools = false
}

bootRun {
    sourceResources sourceSets.main
    classpath = sourceSets.main.runtimeClasspath
}

82 83 84 85 86
wrapper {
    distributionType = Wrapper.DistributionType.BIN
    gradleVersion = "${project.gradleVersion}"
}

87
dependencies {
Misagh Moayyed's avatar
Misagh Moayyed committed
88
    if (project.hasProperty("external")) {
Misagh Moayyed's avatar
Misagh Moayyed committed
89
        compile "org.apereo.cas:cas-server-webapp:${casServerVersion}"
Misagh Moayyed's avatar
Misagh Moayyed committed
90
    } else {
Misagh Moayyed's avatar
Misagh Moayyed committed
91
        compile "org.apereo.cas:cas-server-webapp${project.appServer}:${casServerVersion}"
Misagh Moayyed's avatar
Misagh Moayyed committed
92 93
    }
    // Other dependencies may be listed here...
94 95
}

Misagh Moayyed's avatar
Misagh Moayyed committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
jib {
    from {
        image = "adoptopenjdk/openjdk11:jdk11-alpine-nightly-slim"
    }
    to {
        image = "${project.group}/${project.name}"
        /**
         ecr-login: Amazon Elastic Container Registry (ECR)
         gcr: Google Container Registry (GCR)
         osxkeychain: Docker Hub
         */
        credHelper = "osxkeychain"
        /*
        auth {
            username = "*******"
            password = "*******"
        }
        tags = [casServerVersion]
        */
    }
    container {
        entrypoint = ['docker/entrypoint.sh']
        ports = ['80', '443', '8080', '8443']
        labels = [version:casServerVersion, name:project.name, group:project.group]
    }
    extraDirectory {
        path = file('src/main/jib')
        permissions = [
            '/docker/entrypoint.sh': '755'
        ]
    }
}

task copyWebAppIntoJib(type: Copy, group: "build") {
Misagh Moayyed's avatar
Misagh Moayyed committed
130
    dependsOn build
Misagh Moayyed's avatar
Misagh Moayyed committed
131
    from "build/libs/${casWebApplicationBinaryName}"
132 133 134 135 136 137
    into "src/main/jib/docker/cas/war"
}

task copyConfigIntoJib(type: Copy, group: "build") {
    dependsOn build
    from "etc/cas"
Misagh Moayyed's avatar
Misagh Moayyed committed
138 139 140 141 142 143 144 145
    into "src/main/jib/docker/cas"
}

task deleteWebAppFromJib(type: Delete, group: "build") {
    delete "src/main/jib/docker/cas"
}

tasks.findByName("jibDockerBuild")
146
        .dependsOn(copyWebAppIntoJib, copyConfigIntoJib)
Misagh Moayyed's avatar
Misagh Moayyed committed
147 148 149 150 151
        .finalizedBy(deleteWebAppFromJib)

task explodeWar(type: Copy, group: "build", description: "Explodes the CAS web application archive") {
    dependsOn build
    from zipTree("build/libs/${casWebApplicationBinaryName}")
Misagh Moayyed's avatar
Misagh Moayyed committed
152
    into "${buildDir}/cas"
153 154 155 156 157
}

task run(group: "build", description: "Run the CAS web application in embedded container mode") {
    dependsOn build
    doLast {
158
        def casRunArgs = Arrays.asList("-Xmx2048M -XX:+TieredCompilation -XX:TieredStopAtLevel=1".split(" "))
159
        javaexec {
160
            main = "-jar"
161
            jvmArgs = casRunArgs
Misagh Moayyed's avatar
Misagh Moayyed committed
162
            args = ["build/libs/${casWebApplicationBinaryName}"]
163 164 165 166 167
            logger.info "Started ${commandLine}"
        }
    }
}

168
task debug(group: "build", description: "Debug the CAS web application in embedded mode on port 5005") {
169 170
    dependsOn build
    doLast {
171
        def casArgs = Arrays.asList("-Xmx2048M".split(" "))
172
        javaexec {
173
            main = "-jar"
174 175
            jvmArgs = casArgs
            debug = true
Misagh Moayyed's avatar
Misagh Moayyed committed
176
            args = ["build/libs/${casWebApplicationBinaryName}"]
177 178 179 180 181
            logger.info "Started ${commandLine}"
        }
    }
}

Misagh Moayyed's avatar
Misagh Moayyed committed
182
task downloadShell (group: "shell", description: "Download CAS shell jar from snapshot or release maven repo") {
183
    doFirst {
Misagh Moayyed's avatar
Misagh Moayyed committed
184
        mkdir "${project.shellDir}"
185
    }
186
    doLast {
Misagh Moayyed's avatar
Misagh Moayyed committed
187 188 189
        def downloadFile
        if (isRunningCasServerSnapshot()) {
            def snapshotDir = "https://oss.sonatype.org/content/repositories/snapshots/org/apereo/cas/cas-server-support-shell/${casServerVersion}/"
190 191 192
            def files = new org.apache.ivy.util.url.ApacheURLLister().listFiles(new URL(snapshotDir))
            files = files.sort{it.path}
            files.each {
Misagh Moayyed's avatar
Misagh Moayyed committed
193
                if (it.path.endsWith(".jar")) {
194 195 196 197
                    downloadFile = it
                }
            }
        } else {
Misagh Moayyed's avatar
Misagh Moayyed committed
198
            downloadFile = "https://repo1.maven.org/maven2/org/apereo/cas/cas-server-support-shell/${casServerVersion}/cas-server-support-shell-${casServerVersion}.jar"
199
        }
Misagh Moayyed's avatar
Misagh Moayyed committed
200
        println "Downloading file: ${downloadFile}"
201 202
        download {
            src downloadFile
Misagh Moayyed's avatar
Misagh Moayyed committed
203
            dest new File("${project.shellDir}", "cas-server-support-shell-${casServerVersion}.jar")
204 205 206 207 208
            overwrite false
        }
    }
}

Misagh Moayyed's avatar
Misagh Moayyed committed
209
task runShell (group: "shell",  description: "Run the CAS shell") {
210 211 212 213 214 215 216
    dependsOn downloadShell
    doLast {
        def casShellArgs = Arrays.asList("-Xmx1500M".split(" "))
        javaexec {
            main = "-jar"
            jvmArgs = casShellArgs
            standardInput = System.in
Misagh Moayyed's avatar
Misagh Moayyed committed
217
            args = ["${project.shellDir}/cas-server-support-shell-${casServerVersion}.jar", "--shell"]
218 219 220 221
        }
    }
}

Misagh Moayyed's avatar
Misagh Moayyed committed
222
task debugShell (group: "shell", description: "Run the CAS shell with debug options, wait for debugger on port 5005") {
223 224 225 226 227 228 229 230
    dependsOn downloadShell
    doLast {
        def casArgs = Arrays.asList("-Xmx1500M ".split(" "))
        javaexec {
            main = "-jar"
            jvmArgs = casArgs
            debug = true
            standardInput = System.in
Misagh Moayyed's avatar
Misagh Moayyed committed
231
            args = ["${project.shellDir}/cas-server-support-shell-${casServerVersion}.jar", "--shell"]
232 233 234 235
        }
    }
}

236 237 238 239 240 241 242
task showConfiguration(group: "build", description: "Show configurations for each dependency, etc") {
    doLast() {
        def cfg = project.hasProperty("configuration") ? project.property("configuration") : "compile"
        configurations.getByName(cfg).each { println it }
    }
}

Misagh Moayyed's avatar
Misagh Moayyed committed
243 244 245 246 247 248
task allDependenciesInsight(group: "build", type: DependencyInsightReportTask, description: "Produce insight information for all dependencies") {}

task allDependencies(group: "build", type: DependencyReportTask, description: "Display a graph of all project dependencies") {}

task casVersion (group: "build", description: "Display the current CAS version") {
    doFirst { println casServerVersion }
249 250
}

Misagh Moayyed's avatar
Misagh Moayyed committed
251 252 253
def isRunningCasServerSnapshot() {
    return "${casServerVersion}".contains("-SNAPSHOT")
}