build.gradle 7.35 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 130
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
131
    dependsOn build
Misagh Moayyed's avatar
Misagh Moayyed committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
    from "build/libs/${casWebApplicationBinaryName}"
    into "src/main/jib/docker/cas"
}

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

tasks.findByName("jibDockerBuild")
        .dependsOn(copyWebAppIntoJib)
        .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
147
    into "${buildDir}/cas"
148 149 150 151 152
}

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

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

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

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

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

231 232 233 234 235 236 237
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
238 239 240 241 242 243
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 }
244 245
}

Misagh Moayyed's avatar
Misagh Moayyed committed
246 247 248
def isRunningCasServerSnapshot() {
    return "${casServerVersion}".contains("-SNAPSHOT")
}