Skip to content
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .github/workflows/ado_artifacts_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
inputs:
version:
description: 'Version to publish'
description: Version to publish
required: true
type: string
push:
Expand All @@ -13,7 +13,7 @@ on:

jobs:
PublishToAzureArtifacts:
runs-on: ubuntu-latest
runs-on: ubuntu-latest

steps:
- name: Checkout code
Expand All @@ -24,15 +24,14 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v5
with:
distribution: 'temurin'
distribution: temurin
java-version: 17
cache: 'gradle'
cache: gradle

- name: Publish to Azure DevOps Artifacts
run: |
./gradlew publish
env:
AZURE_DEVOPS_ARTIFACT_USERNAME: ${{ secrets.AZURE_DEVOPS_ARTIFACT_USERNAME }}
AZURE_DEVOPS_ARTIFACT_TOKEN: ${{ secrets.AZURE_DEVOPS_ARTIFACT_TOKEN }}
RELEASE_VERSION: ${{ inputs.version || github.ref_name }}
run: ./gradlew publish
shell: bash
37 changes: 22 additions & 15 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,30 @@ name: Java CI
on:
pull_request:
push:
branches:
- main
Comment thread
Michael1142 marked this conversation as resolved.
Outdated

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v5
with:
java-version: 17
distribution: 'temurin'
- name: Build
run: ./gradlew check -i
- name: Release
env:
GRADLE_PLUGIN_PORTAL_KEY: ${{ secrets.GRADLE_PLUGIN_PORTAL_KEY }}
GRADLE_PLUGIN_PORTAL_SECRET: ${{ secrets.GRADLE_PLUGIN_PORTAL_SECRET }}
RELEASE_VERSION: ${{ github.ref }}
run: ./gradlew publishPlugins
if: startsWith(github.ref, 'refs/tags')
- uses: actions/checkout@v6
- name: Set up JDK
uses: actions/setup-java@v5
with:
java-version: 17
distribution: temurin
cache: gradle
- name: Cache dependency-check data
uses: actions/cache@v5
with:
path: |
~/.gradle/dependency-check-data
build/tmp/integrationTest/work/.gradle-test-kit/dependency-check-data
key: dependency-check-${{ runner.os }}-${{ hashFiles('build.gradle', 'gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
dependency-check-${{ runner.os }}-
- name: Build
env:
NVD_API_KEY: ${{ secrets.NVD_API_KEY }}
run: ./gradlew check -i
56 changes: 26 additions & 30 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
plugins {
id 'java-gradle-plugin'
id 'groovy'
id 'com.gradle.plugin-publish' version '1.3.1'
id "uk.gov.hmcts.java" version "0.12.67"
id 'maven-publish'
id "uk.gov.hmcts.java" version "0.12.70"
}

repositories {
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url = "https://plugins.gradle.org/m2/" }
}

dependencies {
implementation 'org.owasp:dependency-check-gradle:12.2.0'
implementation 'org.apache.maven:maven-artifact:3.9.12'
compileOnly 'org.projectlombok:lombok:1.18.42'
annotationProcessor 'org.projectlombok:lombok:1.18.42'
implementation 'org.apache.maven:maven-artifact:3.9.16'
implementation 'org.owasp:dependency-check-gradle:12.2.2'

testImplementation group: 'com.google.guava', name: 'guava', version: '33.5.0-jre'
testImplementation group: 'commons-io', name: 'commons-io', version: '2.21.0'
compileOnly 'org.projectlombok:lombok:1.18.46'
annotationProcessor 'org.projectlombok:lombok:1.18.46'

testImplementation 'org.spockframework:spock-core:2.3-groovy-3.0'
testImplementation gradleTestKit()
testImplementation 'org.spockframework:spock-core:2.4-groovy-4.0'

testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

java {
Expand All @@ -35,14 +36,12 @@ group = 'uk.gov.hmcts.reform'
project.version = System.getenv("RELEASE_VERSION")?.replace("refs/tags/", "") ?: "DEV-SNAPSHOT"

gradlePlugin {
// Define the plugin
plugins {
greeting {
hmctsJava {
id = 'uk.gov.hmcts.java'
implementationClass = 'uk.gov.hmcts.JavaPlugin'
displayName = 'HMCTS Java standards plugin'
description = 'Applies HMCTS Java coding standards'
tags.set(['hmcts'])
}
}
}
Expand All @@ -56,6 +55,11 @@ sourceSets {

gradlePlugin.testSourceSets(sourceSets.integrationTest)
configurations.integrationTestImplementation.extendsFrom(configurations.testImplementation)
configurations.integrationTestRuntimeOnly.extendsFrom(configurations.testRuntimeOnly)

tasks.withType(Test).configureEach {
useJUnitPlatform()
}

tasks.register('integrationTest', Test) {
testClassesDirs = sourceSets.integrationTest.output.classesDirs
Expand All @@ -68,26 +72,18 @@ check {
dependsOn(tasks.integrationTest)
}

gradlePlugin {
website = 'https://github.com/hmcts/gradle-java-plugin'
vcsUrl = 'https://github.com/hmcts/gradle-java-plugin'
}

ext['gradle.publish.key'] = System.getenv('GRADLE_PLUGIN_PORTAL_KEY')
ext['gradle.publish.secret'] = System.getenv('GRADLE_PLUGIN_PORTAL_SECRET')

// The tests use copies of this build.
tasks.integrationTest.inputs.files file('test-projects')

publishing {
repositories {
maven {
name = "AzureArtifacts"
url = uri("https://pkgs.dev.azure.com/hmcts/Artifacts/_packaging/hmcts-lib/maven/v1")
credentials {
username = System.getenv("AZURE_DEVOPS_ARTIFACT_USERNAME")
password = System.getenv("AZURE_DEVOPS_ARTIFACT_TOKEN")
}
repositories {
maven {
name = "AzureArtifacts"
url = uri("https://pkgs.dev.azure.com/hmcts/Artifacts/_packaging/hmcts-lib/maven/v1")
credentials {
username = System.getenv("AZURE_DEVOPS_ARTIFACT_USERNAME")
password = System.getenv("AZURE_DEVOPS_ARTIFACT_TOKEN")
}
}
}
}
}
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m
org.gradle.workers.max=1
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
25 changes: 13 additions & 12 deletions src/integrationTest/groovy/uk/gov/hmcts/EndToEndTest.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.gov.hmcts

import groovy.xml.XmlSlurper
import org.apache.commons.io.FileUtils
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
Expand All @@ -9,21 +10,21 @@ import spock.lang.TempDir
// Test plugin against a complete Java library project.
class EndToEndTest extends Specification {
@TempDir
File projectFolder;
File projectFolder

def setup() {
File testLibrary = new File("test-projects/test-library")
FileUtils.copyDirectory(testLibrary, projectFolder.getRoot())
FileUtils.copyDirectory(testLibrary, projectFolder)
}

def "All tasks run successfully"() {
def "All tasks run successfully with Gradle #gradleVersion"() {
when:
def result = GradleRunner.create()
.forwardOutput()
.withPluginClasspath()
.withArguments("check", "cleanSuppressions", "-is", "assertRepositoriesOrdered")
.withGradleVersion(gradleVersion)
.withProjectDir(projectFolder.getRoot())
.withProjectDir(projectFolder)
.build()

then:
Expand All @@ -32,28 +33,28 @@ class EndToEndTest extends Specification {
":cleanSuppressions",
":assertRepositoriesOrdered"
)
// The test project declares checkstyle 8.32
result.output =~ "Running Checkstyle 8.32"

// The test project declares checkstyle
result.output =~ /Running Checkstyle \d+\.\d+(\.\d+)?/

where:
gradleVersion << [
"5.0",
"6.0"
"8.14.3",
"9.0.0"
]
}

def "Cleans unused dependency suppressions"() {
when:
GradleRunner.create()
.forwardOutput()
.withDebug(true)
.withPluginClasspath()
.withArguments("cleanSuppressions", "-is")
.withGradleVersion("5.0")
.withProjectDir(projectFolder.getRoot())
.withGradleVersion("9.0.0")
.withProjectDir(projectFolder)
.build()

def cleanSuppressions = new File(projectFolder.root, "suppressions.xml")
def cleanSuppressions = new File(projectFolder, "suppressions.xml")
def doc = new XmlSlurper().parse(cleanSuppressions)

then:
Expand Down
Loading