Skip to content

Commit

Permalink
modularize build (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredsburrows authored Apr 23, 2022
1 parent 20edd4b commit 1908d6f
Show file tree
Hide file tree
Showing 67 changed files with 119 additions and 106 deletions.
161 changes: 59 additions & 102 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import java.time.format.DateTimeFormatter

plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.dokka)
alias(libs.plugins.ktlint)
alias(libs.plugins.maven.publish)
alias(libs.plugins.plugin.publish)
alias(libs.plugins.dokka) apply false
alias(libs.plugins.ktlint) apply false
alias(libs.plugins.maven.publish) apply false
alias(libs.plugins.plugin.publish) apply false
alias(libs.plugins.versions)
id 'java-gradle-plugin'
id 'java-library'
Expand All @@ -18,13 +18,6 @@ repositories {
google()
}

group = GROUP
version = VERSION_NAME
description = POM_DESCRIPTION

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

configurations.configureEach {
resolutionStrategy {
eachDependency { details ->
Expand All @@ -35,112 +28,76 @@ configurations.configureEach {
}
}

task createClasspathManifest() {
def outputDir = new File(buildDir, name)

inputs.files sourceSets.main.runtimeClasspath
outputs.dir outputDir

doLast {
outputDir.mkdirs()
// Combine both main and test plugin classpaths
file("$outputDir/plugin-classpath.txt").text = sourceSets.main.runtimeClasspath.join('\n') +
'\n' + sourceSets.test.runtimeClasspath.join('\n')
subprojects {
repositories {
mavenCentral()
google()
}
}

dependencies {
compileOnly gradleApi()
compileOnly libs.android.plugin

implementation(platform(libs.kotlin.bom))
implementation libs.kotlin.stdlib
implementation libs.kotlinx.html
implementation libs.gson
implementation libs.maven.model

testRuntimeOnly files(createClasspathManifest)
testRuntimeOnly libs.android.plugin

testImplementation localGroovy()
testImplementation gradleTestKit()
testImplementation libs.spock, { exclude module: 'groovy-all' } // Use localGroovy()
testImplementation libs.xmlunit
testImplementation libs.commons
}
tasks.withType(Jar).configureEach {
def dateFile = new File(buildDir, 'jar-manifest-date.txt')
if (!dateFile.exists()) {
def date = DateTimeFormatter.ofPattern('EEE MMM dd HH:mm:ss zzz yyyy').
format(ZonedDateTime.now())
dateFile.parentFile.mkdirs()
dateFile.text = date.trim()
}

gradlePlugin {
plugins {
licensePlugin {
id = PLUGIN_NAME
implementationClass = PLUGIN_NAME_CLASS
manifest {
attributes(
'Created-By': POM_DEVELOPER_NAME,
'Implementation-Title': POM_NAME,
'Implementation-Version': VERSION_NAME,
'Implementation-Vendor': POM_DEVELOPER_NAME,
'Built-By': System.getProperty('user.name'),
'Built-Date': dateFile.text.trim(),
'Built-JDK': System.getProperty('java.version'),
'Built-Gradle': gradle.gradleVersion)
}
}
}

tasks.withType(Jar).configureEach {
def dateFile = new File(buildDir, 'jar-manifest-date.txt')
if (!dateFile.exists()) {
def date = DateTimeFormatter.ofPattern('EEE MMM dd HH:mm:ss zzz yyyy').
format(ZonedDateTime.now())
dateFile.parentFile.mkdirs()
dateFile.text = date.trim()
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
}

manifest {
attributes(
'Created-By': POM_DEVELOPER_NAME,
'Implementation-Title': POM_NAME,
'Implementation-Version': VERSION_NAME,
'Implementation-Vendor': POM_DEVELOPER_NAME,
'Built-By': System.getProperty('user.name'),
'Built-Date': dateFile.text.trim(),
'Built-JDK': System.getProperty('java.version'),
'Built-Gradle': gradle.gradleVersion)
}
}
tasks.withType(JavaCompile).configureEach {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
configure(options) {
compilerArgs << '-Xlint:all'
compilerArgs << '-Xlint:-options'
encoding = 'utf-8'
fork = true
}
}
}

tasks.withType(JavaCompile).configureEach {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
tasks.withType(GroovyCompile).configureEach {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

configure(options) {
compilerArgs << '-Xlint:all'
compilerArgs << '-Xlint:-options'
encoding = 'utf-8'
fork = true
configure(options) {
compilerArgs << '-Xlint:all'
compilerArgs << '-Xlint:-options'
encoding = 'utf-8'
fork = true
}
}
}

tasks.withType(GroovyCompile).configureEach {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
tasks.withType(Test).configureEach {
useJUnitPlatform()

configure(options) {
compilerArgs << '-Xlint:all'
compilerArgs << '-Xlint:-options'
encoding = 'utf-8'
fork = true
}
}

tasks.withType(Test).configureEach {
useJUnitPlatform()
testLogging {
exceptionFormat 'full'
showCauses true
showExceptions true
showStackTraces true
events 'failed', 'skipped'
}

testLogging {
exceptionFormat 'full'
showCauses true
showExceptions true
showStackTraces true
events 'failed', 'skipped'
def maxWorkerCount = gradle.startParameter.maxWorkerCount
maxParallelForks = (maxWorkerCount < 2) ? 1 : maxWorkerCount / 2
}

def maxWorkerCount = gradle.startParameter.maxWorkerCount
maxParallelForks = (maxWorkerCount < 2) ? 1 : maxWorkerCount / 2
}
54 changes: 54 additions & 0 deletions gradle-license-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.dokka)
alias(libs.plugins.ktlint)
alias(libs.plugins.maven.publish)
alias(libs.plugins.plugin.publish)
alias(libs.plugins.versions)
id 'java-gradle-plugin'
id 'java-library'
id 'groovy'
}

task createClasspathManifest() {
def outputDir = new File(buildDir, name)

inputs.files sourceSets.main.runtimeClasspath
outputs.dir outputDir

doLast {
outputDir.mkdirs()
// Combine both main and test plugin classpaths
file("$outputDir/plugin-classpath.txt").text = sourceSets.main.runtimeClasspath.join('\n') +
'\n' + sourceSets.test.runtimeClasspath.join('\n')
}
}

dependencies {
compileOnly gradleApi()
compileOnly libs.android.plugin

implementation(platform(libs.kotlin.bom))
implementation libs.kotlin.stdlib
implementation libs.kotlinx.html
implementation libs.gson
implementation libs.maven.model

testRuntimeOnly files(createClasspathManifest)
testRuntimeOnly libs.android.plugin

testImplementation localGroovy()
testImplementation gradleTestKit()
testImplementation libs.spock, { exclude module: 'groovy-all' } // Use localGroovy()
testImplementation libs.xmlunit
testImplementation libs.commons
}

gradlePlugin {
plugins {
licensePlugin {
id = PLUGIN_NAME
implementationClass = PLUGIN_NAME_CLASS
}
}
}
3 changes: 3 additions & 0 deletions gradle-license-plugin/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POM_ARTIFACT_ID=gradle-license-plugin
POM_NAME=Gradle License Plugin
POM_DESCRIPTION=Gradle plugin that provides a task to generate a HTML license report of your project.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 0 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
GROUP=com.jaredsburrows
POM_ARTIFACT_ID=gradle-license-plugin
VERSION_NAME=0.9.1-SNAPSHOT

POM_NAME=Gradle License Plugin
POM_DESCRIPTION=Gradle plugin that provides a task to generate a HTML license report of your project.
POM_INCEPTION_YEAR=2016
POM_PACKAGING=jar
POM_URL=https://github.com/jaredsburrows/gradle-license-plugin
Expand Down
4 changes: 3 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'com.gradle.enterprise' version '3.6.4'
id 'com.gradle.enterprise' version '3.10'
}

gradleEnterprise {
Expand All @@ -11,3 +11,5 @@ gradleEnterprise {
}

rootProject.name = 'gradle-license-plugin'

include ':gradle-license-plugin'
Empty file.

0 comments on commit 1908d6f

Please sign in to comment.