Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup Gradle build #997

Merged
merged 3 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ subprojects {
sourceCompatibility = 11
targetCompatibility = 11

tasks.withType(Checkstyle) {
tasks.withType(Checkstyle).configureEach {
enabled = false
}

tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.errorprone.disable 'PreconditionsConstantMessage', 'PreferSafeLoggableExceptions', 'PreferSafeLoggingPreconditions'
}

// Run `./gradlew test -Drecreate=true` to recreate all the expected
// generated code that we have checked into the repo.
tasks.withType(Test) {
tasks.withType(Test).configureEach {
systemProperty 'recreate', System.getProperty('recreate', 'false')
}
}
Expand Down
8 changes: 3 additions & 5 deletions eclipse_plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,15 @@ dependencies {
implementation project(':palantir-java-format')
}

jar {
tasks.named("jar", Jar) {
archiveBaseName = 'palantir-java-format-eclipse-plugin'
manifest {
from 'src/main/resources/META-INF/MANIFEST.MF'
}
// We embed some dependencies into the JAR file
from(configurations.runtimeClasspath.filter {
var name = it.getName()
name.startsWith('functionaljava') || name.startsWith('guava') || name.startsWith('palantir')
}) {
from(configurations.runtimeClasspath) {
into 'lib'
include('functionaljava*', 'guava*', 'palantir*')
// The libraries are listed without a version in the manifest
rename('(.*)-[0-9b.]+(\\.dirty|-jre)?\\.jar', '$1.jar')
}
Expand Down
52 changes: 23 additions & 29 deletions gradle-palantir-java-format/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ apply plugin: 'com.palantir.external-publish-gradle-plugin'
apply plugin: 'com.palantir.revapi'

configurations {
implicitDependencies
pluginClasspath
pluginClasspath {
canBeConsumed = false
canBeResolved = true
}
}

dependencies {
compileOnly 'com.diffplug.spotless:spotless-plugin-gradle'

implementation gradleApi()
implementation 'com.google.guava:guava'
implementation project(':palantir-java-format-spi')
Expand All @@ -21,75 +25,65 @@ dependencies {
testImplementation 'org.assertj:assertj-core'
testImplementation project(':palantir-java-format')

// Have to configure this manually in order to resolve the implicitDependencies together with runtimeClasspath
// This is to allow both our code and spotless to end up on the same class loader in tests.
// Ordinarily when running, these would end up on the same classloader
pluginClasspath configurations.implicitDependencies
pluginClasspath configurations.runtimeClasspath
pluginClasspath sourceSets.main.output
compileOnly configurations.implicitDependencies
implicitDependencies 'com.diffplug.spotless:spotless-plugin-gradle'
pluginClasspath 'com.diffplug.spotless:spotless-plugin-gradle'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you'd like to only see com.diffplug.spotless:spotless-plugin-gradle only defined once, a quick way to achieve this is by modifying the pluginClasspath configuration above to have an extendsFrom compileOnly.

}

gradlePlugin {
website = 'https://github.com/palantir/palantir-java-format/'
vcsUrl = 'https://github.com/palantir/palantir-java-format/'
plugins {
palantirJavaFormat {
id = 'com.palantir.java-format'
implementationClass = 'com.palantir.javaformat.gradle.PalantirJavaFormatPlugin'
description = 'A modern, lambda-friendly, 120 character Java formatter. Applies all other palantir-java-format plugins.'
displayName = 'Palantir Java Format'
tags.set(['java', 'style'])
}
palantirJavaFormatIdea {
id = 'com.palantir.java-format-idea'
implementationClass = 'com.palantir.javaformat.gradle.PalantirJavaFormatIdeaPlugin'
description = 'Plugin to configure the PalantirJavaFormat IDEA plugin based on an optional implementation version of the formatter.'
displayName = 'Palantir Java Format Idea'
tags.set(['java', 'style'])
}
palantirJavaFormatSpotless {
id = 'com.palantir.java-format-spotless'
implementationClass = 'com.palantir.javaformat.gradle.PalantirJavaFormatSpotlessPlugin'
description = 'If spotless is applied, configures a java step that formats using palantir-java-format.'
displayName = 'Palantir Java Format Spotless'
tags.set(['java', 'style'])
}
palantirJavaFormatProvider {
id = 'com.palantir.java-format-provider'
implementationClass = 'com.palantir.javaformat.gradle.PalantirJavaFormatProviderPlugin'
description = 'Exposes a configuration containing the palantir-java-format jars'
displayName = 'Palantir Java Format Provider'
tags.set(['java', 'style'])
}
}
}

pluginBundle {
website = 'https://github.com/palantir/palantir-java-format/'
vcsUrl = 'https://github.com/palantir/palantir-java-format/'
description = 'Palantir Java Format is an opinionated lambda friendly formatter for java.'
tags = ['java', 'style']
}

tasks.withType(PluginUnderTestMetadata) {
pluginClasspath.from = configurations.pluginClasspath
}

idea {
module {
sourceDirs += sourceSets.main.groovy.srcDirs
}
tasks.withType(PluginUnderTestMetadata).configureEach {
pluginClasspath.from += configurations.pluginClasspath
}

configurations {
impl
impl {
canBeConsumed = false
canBeResolved = true
}
}

dependencies {
impl project(':palantir-java-format')
}

task writeImplClasspath {
dependsOn configurations.impl
def writeImplClasspath = tasks.register("writeImplClasspath") {
doLast {
file("$buildDir/impl.classpath").text = configurations.impl.asPath
}
}

test.dependsOn tasks.writeImplClasspath
tasks.named("test").configure {
dependsOn(writeImplClasspath)
}
34 changes: 24 additions & 10 deletions idea-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ intellij {
plugins = ['java']
}

tasks.runIde {
def buildPlugin = tasks.named("buildPlugin")

tasks.named("runIde") {
// Allow debugging
jvmArgs '--add-exports=java.base/jdk.internal.vm=ALL-UNNAMED'

dependsOn(buildPlugin)
}

patchPluginXml {
Expand All @@ -39,15 +43,21 @@ patchPluginXml {
untilBuild = ''
}

publishPlugin {
def publishPlugin = tasks.named("publishPlugin") {
onlyIf { versionDetails().isCleanTag }

token = System.env.JETBRAINS_PLUGIN_REPO_TOKEN
}
tasks.publishPlugin.onlyIf { versionDetails().isCleanTag }
tasks.publish.dependsOn publishPlugin
tasks.named("publish") {
dependsOn(publishPlugin)
}

configurations {
formatter {
description = 'The default implementation of palantir-java-format, used if the user doesn\'t specify an explicit classpath.'

canBeConsumed = false
canBeResolved = true
}
}

Expand All @@ -73,11 +83,13 @@ tasks.withType(JavaCompile).configureEach {
options.errorprone.disable 'PreferSafeLoggingPreconditions'
}

check.dependsOn buildPlugin, verifyPlugin
tasks.named("check") {
dependsOn(buildPlugin, tasks.named("verifyPlugin"))
}
// This task will resolve runtimeClasspath without telling Gradle that it depends on it, therefore dependent jars won't
// be created beforehand. Therefore, ensure that it knows about it.
// see https://github.com/JetBrains/gradle-intellij-plugin/blob/master/src/main/groovy/org/jetbrains/intellij/tasks/PrepareSandboxTask.groovy
tasks.withType(org.jetbrains.intellij.tasks.PrepareSandboxTask) {
tasks.withType(org.jetbrains.intellij.tasks.PrepareSandboxTask).configureEach {
dependsOn configurations.runtimeClasspath

// Also pack the formatter in its own directory
Expand All @@ -88,9 +100,9 @@ tasks.withType(org.jetbrains.intellij.tasks.PrepareSandboxTask) {
}
}

runIde.dependsOn buildPlugin

buildSearchableOptions.enabled = false
tasks.named("buildSearchableOptions") {
enabled = false
}

// Prevent nebula.maven-publish from trying to publish components.java - we are publishing our own different artifact
ext."nebulaPublish.maven.jar" = false
Expand All @@ -109,4 +121,6 @@ versionsLock {
}

// Javadoc fails if there are no public classes to javadoc, so make it stop complaining.
tasks.javadoc.failOnError = false
tasks.named("javadoc", Javadoc) {
failOnError = false
}
20 changes: 7 additions & 13 deletions palantir-java-format/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import java.util.function.Function
import java.util.stream.Collectors

apply plugin: 'application'
apply plugin: 'com.palantir.external-publish-jar'

Expand Down Expand Up @@ -43,12 +40,7 @@ def exports = [
'jdk.compiler/com.sun.tools.javac.api'
]

def jvmArgList = exports.stream().map(new Function<String, String>() {
@Override
String apply(String value) {
return "--add-exports=${value}=ALL-UNNAMED"
}
}).collect(Collectors.toList())
def jvmArgList = exports.collect { value -> "--add-exports=${value}=ALL-UNNAMED".toString() }

tasks.withType(JavaCompile).configureEach {
options.errorprone.disable 'StrictUnusedVariable'
Expand All @@ -75,9 +67,11 @@ tasks.withType(Javadoc).configureEach {
}

// false positives due to org.junit.runners.* in the test cases
tasks.checkJUnitDependencies.enabled = false
tasks.named("checkJUnitDependencies") {
enabled = false
}

tasks.test {
tasks.named("test") {
// Run all classes and tests in parallel
// https://junit.org/junit5/docs/current/user-guide/#writing-tests-parallel-execution
systemProperty 'junit.jupiter.execution.parallel.mode.default', 'concurrent'
Expand All @@ -90,8 +84,8 @@ idea {

// This block may be replaced by BaselineExportsExtension exports
// once https://github.com/gradle/gradle/issues/18824 is resolved.
jar {
tasks.named("jar", Jar) {
manifest {
attributes('Add-Exports': exports.stream().collect(Collectors.joining(' ')))
attributes('Add-Exports': exports.join(' '))
}
}
Loading