build.gradle 7.76 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:${project.gradleDownloadTaskVersion}" // used to download CAS shell
        classpath "org.apache.ivy:ivy:${project.ivyVersion}" // used to download CAS shell from snapshot repo
        classpath "gradle.plugin.com.google.cloud.tools:jib-gradle-plugin:${project.jibVersion}"
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
        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'
        ]
    }
}

Misagh Moayyed's avatar
Misagh Moayyed committed
130 131 132 133 134 135 136 137
task copyCasConfiguration(type: Copy, group: "build") {
    from "etc/cas/config"
    into "/etc/cas/config"
    doFirst {
        mkdir "/etc/cas/config"
    }
}

Misagh Moayyed's avatar
Misagh Moayyed committed
138
task copyWebAppIntoJib(type: Copy, group: "build") {
Misagh Moayyed's avatar
Misagh Moayyed committed
139
    dependsOn build
Misagh Moayyed's avatar
Misagh Moayyed committed
140
    from "build/libs/${casWebApplicationBinaryName}"
141 142 143 144 145 146
    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
147 148 149 150 151 152 153 154
    into "src/main/jib/docker/cas"
}

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

tasks.findByName("jibDockerBuild")
155
        .dependsOn(copyWebAppIntoJib, copyConfigIntoJib)
Misagh Moayyed's avatar
Misagh Moayyed committed
156 157 158 159 160
        .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
161
    into "${buildDir}/cas"
162 163 164 165 166
}

task run(group: "build", description: "Run the CAS web application in embedded container mode") {
    dependsOn build
    doLast {
167
        def casRunArgs = Arrays.asList("-Xmx2048M -XX:+TieredCompilation -XX:TieredStopAtLevel=1".split(" "))
168
        javaexec {
169
            main = "-jar"
170
            jvmArgs = casRunArgs
Misagh Moayyed's avatar
Misagh Moayyed committed
171
            args = ["build/libs/${casWebApplicationBinaryName}"]
172 173 174 175 176
            logger.info "Started ${commandLine}"
        }
    }
}

177
task debug(group: "build", description: "Debug the CAS web application in embedded mode on port 5005") {
178 179
    dependsOn build
    doLast {
180
        def casArgs = Arrays.asList("-Xmx2048M".split(" "))
181
        javaexec {
182
            main = "-jar"
183 184
            jvmArgs = casArgs
            debug = true
Misagh Moayyed's avatar
Misagh Moayyed committed
185
            args = ["build/libs/${casWebApplicationBinaryName}"]
186 187 188 189 190
            logger.info "Started ${commandLine}"
        }
    }
}

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

Misagh Moayyed's avatar
Misagh Moayyed committed
218
task runShell (group: "shell",  description: "Run the CAS shell") {
219 220 221 222 223 224 225
    dependsOn downloadShell
    doLast {
        def casShellArgs = Arrays.asList("-Xmx1500M".split(" "))
        javaexec {
            main = "-jar"
            jvmArgs = casShellArgs
            standardInput = System.in
Misagh Moayyed's avatar
Misagh Moayyed committed
226
            args = ["${project.shellDir}/cas-server-support-shell-${casServerVersion}.jar", "--shell"]
227 228 229 230
        }
    }
}

Misagh Moayyed's avatar
Misagh Moayyed committed
231
task debugShell (group: "shell", description: "Run the CAS shell with debug options, wait for debugger on port 5005") {
232 233 234 235 236 237 238 239
    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
240
            args = ["${project.shellDir}/cas-server-support-shell-${casServerVersion}.jar", "--shell"]
241 242 243 244
        }
    }
}

245 246 247 248 249 250 251
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
252 253 254 255 256 257
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 }
258 259
}

260
def isRunningCasServerSnapshot(casServerVersion) {
Misagh Moayyed's avatar
Misagh Moayyed committed
261 262
    return "${casServerVersion}".contains("-SNAPSHOT")
}