Skip to content

Commit

Permalink
Issue916: Switch from Maven to Gradle for builds (#917)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazza authored Aug 3, 2018
1 parent b177980 commit 84e3a5c
Show file tree
Hide file tree
Showing 13 changed files with 496 additions and 665 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: java
script: mvn integration-test
script: ./gradlew clean build

services:
- docker
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Welcome to TightBlog! This project started off in May 2015 as a fork of the Apache Roller project, of which I contributed for about 2 1/2 years
before deciding to go my own way due to differing ideas of what would make the best blogging product. As of 30 July 2018, <a href="https://github.com/gmazza/tightblog/releases">Release 3.1</a> is available.
before deciding to go my own way due to differing ideas of what would make the best blogging product. As of 3 August 2018, <a href="https://github.com/gmazza/tightblog/releases">Release 3.1.1</a> is available.

Screen shots for the TightBlog UI are [here](https://github.com/gmazza/tightblog/wiki/Screenshots), the twelve-table database model is
[here](https://github.com/gmazza/tightblog/blob/master/app/src/main/resources/dbscripts/createdb.vm), see also [my blog](https://glenmazza.net/blog/) for an example
Expand Down Expand Up @@ -40,8 +40,8 @@ To obtain the source code:
* Release 2.0.x branch: https://github.com/gmazza/tightblog/tree/release2.0.4
* source for a specific release: https://github.com/gmazza/tightblog/releases

To build the application (app/target/tightblog.war) with Maven and Java 8:
`mvn clean install` from the TightBlog root.
To build the application (app/target/tightblog.war) with Gradle and Java 8:
`gradle clean build` from the TightBlog root.

The Docker images defined in the docker subdirectory of this project can be used to test TightBlog locally before deploying. First build
the project to generate the tightblog WAR. As TightBlog requires SSL, next provide a certificate & key for the Tomcat
Expand Down
214 changes: 214 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
buildscript {
repositories {
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath 'com.bmuschko:gradle-docker-plugin:3.2.3'
}
}

plugins {
id 'com.bmuschko.docker-remote-api' version '3.2.3'
}

apply plugin: 'war'
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'checkstyle'
apply plugin: 'groovy'
apply plugin: com.bmuschko.gradle.docker.DockerRemoteApiPlugin

group = 'org.tightblog'
version = '3.1.1'

description = """TightBlog"""

sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

repositories {
maven { url "http://repo.maven.apache.org/maven2" }
}

sourceSets {
test {
java {
srcDir 'src/test/java'
exclude '**/*IT.java'
}
}
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/test/java')
include '**/*IT.java'
}
resources.srcDir file('src/test/resources')
}
}

def itDatabasePort = 32794
def buildNumber = Instant.now().getEpochSecond()

task createDDLScripts (dependsOn: 'classes', type: JavaExec) {
main = 'genDDL'
classpath = sourceSets.main.runtimeClasspath
}

processResources {
filesMatching(['tightblog.properties', 'tightblog-custom.properties']) {
expand(version: version,
buildNumber: buildNumber,
itDatabasePort: itDatabasePort,
buildDir: buildDir
)
}
}

processTestResources {
filesMatching(['tightblog.properties', 'tightblog-custom.properties']) {
expand(version: version,
buildNumber: buildNumber,
itDatabasePort: itDatabasePort,
buildDir: buildDir
)
}
}

processIntegrationTestResources {
filesMatching(['tightblog.properties', 'tightblog-custom.properties']) {
expand(version: version,
buildNumber: buildNumber,
itDatabasePort: itDatabasePort,
buildDir: buildDir
)
}
}


configurations {
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime
}

import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
import com.bmuschko.gradle.docker.tasks.container.DockerCreateContainer
import com.bmuschko.gradle.docker.tasks.container.DockerStartContainer
import com.bmuschko.gradle.docker.tasks.container.DockerStopContainer
import com.bmuschko.gradle.docker.tasks.container.extras.DockerWaitHealthyContainer

import java.time.Instant

// https://bmuschko.com/blog/dockerized-spring-boot-app/
task buildImage(type: DockerBuildImage) {
inputDir = file('src/test/resources')
tag = "tightblog/it-database123:latest"
}

// variant of https://bmuschko.com/blog/docker-integration-testing/
task createContainer(type: DockerCreateContainer) {
dependsOn buildImage
targetImageId { buildImage.getImageId() }
portBindings = [itDatabasePort + ':5432']
}

task startContainer(type: DockerStartContainer) {
dependsOn createContainer
targetContainerId { createContainer.getContainerId() }
}

task startAndWaitOnHealthyContainer(type: DockerWaitHealthyContainer) {
dependsOn startContainer
timeout = 60
targetContainerId { createContainer.getContainerId() }
}

task stopContainer(type: DockerStopContainer) {
targetContainerId { createContainer.getContainerId() }
}

task integrationTest(type: Test) {
dependsOn startAndWaitOnHealthyContainer
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
outputs.upToDateWhen { false }
mustRunAfter test
finalizedBy stopContainer
}

war.dependsOn createDDLScripts
check.dependsOn integrationTest


checkstyle {
toolVersion = "8.9"
config = resources.text.fromFile('checkstyle.xml', 'UTF-8')
showViolations = true
ignoreFailures = false
}

dependencies {
compile localGroovy()
compile group: 'org.eclipse.persistence', name: 'org.eclipse.persistence.jpa', version:'2.7.2'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version:'2.11.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version:'2.11.0'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version:'4.5.6'
compile group: 'org.hibernate', name: 'hibernate-validator', version:'5.4.1.Final'
compile group: 'org.hibernate', name: 'hibernate-validator-cdi', version:'5.4.1.Final'
compile group: 'org.glassfish', name: 'javax.el', version:'3.0.1-b10'
compile group: 'com.github.ben-manes.caffeine', name: 'caffeine', version:'2.6.2'
compile group: 'org.jsoup', name: 'jsoup', version:'1.11.3'
compile group: 'com.atlassian.commonmark', name: 'commonmark', version:'0.11.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-jcl', version:'2.11.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version:'2.11.0'
compile group: 'org.apache.lucene', name: 'lucene-analyzers-common', version:'7.4.0'
compile group: 'org.apache.lucene', name: 'lucene-queryparser', version:'7.4.0'
compile group: 'org.apache.tiles', name: 'tiles-jsp', version:'3.0.8'
compile group: 'org.apache.commons', name: 'commons-lang3', version:'3.7'
compile group: 'org.apache.commons', name: 'commons-text', version:'1.4'
compile group: 'commons-fileupload', name: 'commons-fileupload', version:'1.3.3'
compile(group: 'org.springframework', name: 'spring-web', version:'5.0.8.RELEASE') {
exclude(module: 'aopalliance')
}
compile group: 'org.springframework', name: 'spring-context', version:'5.0.8.RELEASE'
compile group: 'org.springframework', name: 'spring-context-support', version:'5.0.8.RELEASE'
compile group: 'org.springframework', name: 'spring-webmvc', version:'5.0.8.RELEASE'
compile group: 'org.springframework', name: 'spring-jdbc', version:'5.0.8.RELEASE'
compile group: 'org.springframework.security', name: 'spring-security-config', version:'5.0.7.RELEASE'
compile group: 'org.springframework.mobile', name: 'spring-mobile-device', version:'1.1.5.RELEASE'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version:'2.9.6'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version:'2.9.6'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version:'2.9.6'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version:'2.9.6'
compile(group: 'org.springframework.security', name: 'spring-security-taglibs', version:'5.0.7.RELEASE') {
exclude(module: 'spring-web')
}
compile(group: 'org.springframework.security', name: 'spring-security-acl', version:'5.0.7.RELEASE') {
exclude(module: 'spring-jdbc')
}
compile group: 'org.jboss.aerogear', name: 'aerogear-otp-java', version:'1.0.0'
compile group: 'javax.servlet', name: 'jstl', version:'1.2'
compile group: 'commons-validator', name: 'commons-validator', version:'1.6'
compile group: 'commons-httpclient', name: 'commons-httpclient', version:'3.1'
compile group: 'commons-beanutils', name: 'commons-beanutils', version:'1.9.3'
compile group: 'commons-codec', name: 'commons-codec', version:'1.11'
compile(group: 'org.thymeleaf', name: 'thymeleaf', version:'3.0.9.RELEASE') {
exclude(module: 'ognl')
}
compile group: 'org.thymeleaf', name: 'thymeleaf-spring4', version:'3.0.9.RELEASE'
runtime group: 'org.apache.logging.log4j', name: 'log4j-web', version:'2.11.0'
testCompile group: 'org.springframework', name: 'spring-test', version:'5.0.8.RELEASE'
testCompile group: 'org.postgresql', name: 'postgresql', version:'42.2.4'
testCompile group: 'junit', name: 'junit', version:'4.12'
testCompile group: 'org.mockito', name: 'mockito-core', version:'2.20.1'
providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version:'3.1.0'
providedCompile group: 'javax.mail', name: 'javax.mail-api', version:'1.6.1'
providedCompile group: 'javax.servlet.jsp', name: 'jsp-api', version:'2.2'
compile group: 'org.apache.velocity', name: 'velocity-engine-core', version:'2.0'
}
2 changes: 1 addition & 1 deletion docker/web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ ADD http://central.maven.org/maven2/org/postgresql/postgresql/42.2.4/postgresql-
# Note self-signed certificates bring up browser warnings, getting a key from a certificate authority instead is preferred
COPY ./docker/web/server.xml ./docker/web/ssl.crt ./docker/web/ssl.key /usr/local/tomcat/conf/
COPY ./docker/web/tightblog-custom.properties /usr/local/tomcat/lib/
COPY ./app/target/tightblog.war /usr/local/tomcat/webapps/tightblog.war
COPY ./build/libs/tightblog*.war /usr/local/tomcat/webapps/tightblog.war

CMD ["catalina.sh", "run"]
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 84e3a5c

Please sign in to comment.