build.gradle 7.54 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
jib {
    from {
hdeadman's avatar
hdeadman committed
98
        image = project.baseDockerImage
Misagh Moayyed's avatar
Misagh Moayyed committed
99 100 101 102 103 104 105 106 107
    }
    to {
        image = "${project.group}/${project.name}"
        /**
         ecr-login: Amazon Elastic Container Registry (ECR)
         gcr: Google Container Registry (GCR)
         osxkeychain: Docker Hub
         */
        credHelper = "osxkeychain"
Misagh Moayyed's avatar
Misagh Moayyed committed
108
        /**
Misagh Moayyed's avatar
Misagh Moayyed committed
109 110 111 112 113 114 115 116
        auth {
            username = "*******"
            password = "*******"
        }
        tags = [casServerVersion]
        */
    }
    container {
Misagh Moayyed's avatar
Misagh Moayyed committed
117
        useCurrentTimestamp = true
Misagh Moayyed's avatar
Misagh Moayyed committed
118 119 120 121 122 123 124 125 126 127 128 129 130
        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
131
    dependsOn build
Misagh Moayyed's avatar
Misagh Moayyed committed
132
    from "build/libs/${casWebApplicationBinaryName}"
133 134 135 136 137 138
    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
139 140 141 142 143 144 145 146
    into "src/main/jib/docker/cas"
}

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

tasks.findByName("jibDockerBuild")
147
        .dependsOn(copyWebAppIntoJib, copyConfigIntoJib)
Misagh Moayyed's avatar
Misagh Moayyed committed
148 149 150 151 152
        .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
153
    into "${buildDir}/cas"
154 155 156 157 158
}

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

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

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

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

Misagh Moayyed's avatar
Misagh Moayyed committed
223
task debugShell (group: "shell", description: "Run the CAS shell with debug options, wait for debugger on port 5005") {
224 225 226 227 228 229 230 231
    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
232
            args = ["${project.shellDir}/cas-server-support-shell-${casServerVersion}.jar", "--shell"]
233 234 235 236
        }
    }
}

237 238 239 240 241 242 243
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
244 245 246 247 248 249
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 }
250 251
}

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