Skip to content

Commit

Permalink
feat(gradle)!: Extract initialization and defaults to jenkins-plugin-…
Browse files Browse the repository at this point in the history
…resolver plugin
  • Loading branch information
turboBasic committed Jan 6, 2024
1 parent 63252db commit f6e9bea
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 49 deletions.
44 changes: 2 additions & 42 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,12 @@ import org.example.JenkinsPlugins


plugins {
id 'groovy'
id 'idea'
id 'com.adarshr.test-logger'
id 'jenkins-plugin-resolver'
}

group = 'org.example'
version = '1.0-SNAPSHOT'

JenkinsPlugins.create(project)

java {
toolchain {
setLanguageVersion JavaLanguageVersion.of(11)
}
}

sourceSets {
main {
groovy {
Expand All @@ -38,50 +28,20 @@ sourceSets {
}
}

configurations {
testPlugins
}

dependencies {
implementationDependencies delegate
testImplementationDependencies delegate
jenkinsPluginDependencies delegate
junit5Dependencies delegate
}

idea {
module {
downloadJavadoc = true
downloadSources = true
}
}

/* Tasks */

tasks.named('test') {
dependsOn tasks.resolveTestPlugins
inputs.files sourceSets.main.allSource.files
// set build directory for Jenkins test harness, JENKINS-26331
systemProperty 'buildDirectory', buildDir

useJUnitPlatform()
maxParallelForks = 4

final String STACK_WRITE_PROPERTY = 'pipeline.stack.write'
final String LOGLEVEL_PROPERTY = 'testlogger.logLevel'
systemProperty STACK_WRITE_PROPERTY, System.getProperty(STACK_WRITE_PROPERTY) ?: findProperty(STACK_WRITE_PROPERTY)
systemProperty LOGLEVEL_PROPERTY, System.getProperty(LOGLEVEL_PROPERTY) ?: findProperty(LOGLEVEL_PROPERTY)

testlogger {
theme 'mocha-parallel'
showStandardStreams true
showFullStackTraces true
}
reports {
junitXml {
outputPerTestCase = true
}
}
}

tasks.register('resolveTestPlugins', Copy) {
Expand Down Expand Up @@ -118,7 +78,7 @@ tasks.named('wrapper') {

/* Helpers */

void implementationDependencies(DependencyHandler context) {
static void implementationDependencies(DependencyHandler context) {
List<String> dependencies = [
"org.codehaus.groovy:groovy-all:2.4.21",
"org.jenkins-ci.main:jenkins-core:${JenkinsPlugins.get().jenkinsVersion}",
Expand Down
11 changes: 11 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
plugins {
id 'groovy-gradle-plugin'
}

repositories {
gradlePluginPortal() // alias for https://plugins.gradle.org/m2/
}

dependencies {
implementation 'com.adarshr:gradle-test-logger-plugin:4.0.0'
}
Empty file added buildSrc/settings.gradle
Empty file.
51 changes: 51 additions & 0 deletions buildSrc/src/main/groovy/jenkins-plugin-resolver.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import org.example.JenkinsPlugins


plugins {
id 'groovy'
id 'idea'
id 'com.adarshr.test-logger'
}

JenkinsPlugins.create(project)

java {
toolchain {
setLanguageVersion JavaLanguageVersion.of(11)
}
}

idea {
module {
downloadJavadoc = true
downloadSources = true
}
}

configurations {
testPlugins
}

tasks.named('test') {
final String STACK_WRITE_PROPERTY = 'pipeline.stack.write'
final String LOGLEVEL_PROPERTY = 'testlogger.logLevel'
final String JENKINS_TEST_HARNESS_BUILD_DIR_PROPERTY = 'buildDirectory'

systemProperty STACK_WRITE_PROPERTY, System.getProperty(STACK_WRITE_PROPERTY) ?: findProperty(STACK_WRITE_PROPERTY)
systemProperty LOGLEVEL_PROPERTY, System.getProperty(LOGLEVEL_PROPERTY) ?: findProperty(LOGLEVEL_PROPERTY)
systemProperty JENKINS_TEST_HARNESS_BUILD_DIR_PROPERTY, buildDir

useJUnitPlatform()

testlogger {
theme 'mocha-parallel'
showStandardStreams true
showFullStackTraces true
}

reports {
junitXml {
outputPerTestCase = true
}
}
}
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jenkinsVersion = 2.277.4
## Jenkins Test Harness and plugins versions for Jenkins 2.277.4

testHarnessVersion.2.277.4 = 2140.ve736dc2b_b_d2c
# plugins can also be commented out by prepending them with '#'
jenkinsPluginVersions.2.277.4 = \
org.jenkins-ci.plugins.workflow:workflow-cps-global-lib: 2.21 \
org.jenkins-ci.plugins.workflow:workflow-job: 2.41 \
Expand All @@ -29,10 +30,11 @@ jenkinsPluginVersions.2.277.4 = \
org.jenkins-ci.plugins:script-security: 1.77 \
org.jenkins-ci.plugins:structs: 1.23 \
org.jenkins-ci.plugins:trilead-api: 1.0.13 \
\
#org.example.ignored:plugin: 1.0.0 \
#


testLoggerPluginVersion = 4.0.0
# Gradle log levels: ERROR->QUIET->WARN->LIFECYCLE->INFO->DEBUG
testlogger.logLevel = lifecycle

Expand Down
6 changes: 0 additions & 6 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
pluginManagement {
plugins {
id 'com.adarshr.test-logger' version testLoggerPluginVersion
}
}

dependencyResolutionManagement {
repositories {
/* Alias of https://repo1.maven.org/maven2 a.k.a. https://repo.maven.apache.org/maven2/ */
Expand Down

0 comments on commit f6e9bea

Please sign in to comment.