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

Gradle: Multi Compilation 21< and 21 #1079

Closed
Closed
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
90 changes: 84 additions & 6 deletions palantir-java-format/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,95 @@ def exports = [

def jvmArgList = exports.collect { value -> "--add-exports=${value}=ALL-UNNAMED".toString() }

tasks.withType(JavaCompile).configureEach {
options.errorprone.disable 'StrictUnusedVariable'
//register compileJava21 on the same source code
tasks.register("compileJava21", JavaCompile) {
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(21)
}

// Allow access to internal javac apis
options.compilerArgs += jvmArgList
source(sourceSets["main"].java)
classpath = sourceSets["main"].compileClasspath
destinationDirectory.set(sourceSets["main"].java.destinationDirectory)

if (JavaVersion.current() < JavaVersion.VERSION_14) {
excludes = ['**/Java14InputAstVisitor.java']
}

tasks.register("compileTestJava21", JavaCompile) {
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(21)
}

source(sourceSets["test-21"].java)
classpath = sourceSets["test-21"].compileClasspath
destinationDirectory.set(sourceSets["test-21"].java.destinationDirectory)

}

sourceSets {
main {
java {
srcDirs = ['src/main/java']
}
resources {
srcDirs = ['src/main/resources']
}
}
test {
java {
srcDirs = ['src/test/java']
}
resources {
srcDirs = ['src/test/resources']
}
}

'test-21' {
java {
srcDirs = ['src/test-21/java']
}
resources {
srcDirs = ['src/test-21/resources']
}
}

}


tasks.named("classes") {
dependsOn("compileJava21")
}

tasks.named("testClasses") {
dependsOn("compileTestJava21")
}

tasks.withType(JavaCompile).configureEach {
config ->
{

def currentLanguageVersion = config.javaCompiler.get().getMetadata().languageVersion.asInt()
println("JavaCompile name:" + config.name + " version:" + currentLanguageVersion)


options.errorprone.disable 'StrictUnusedVariable'

// Allow access to internal javac apis
options.compilerArgs += jvmArgList

if (currentLanguageVersion < 14) {
excludes = ['**/java14/*.java', '**/java21/*.java']
}
if (14< currentLanguageVersion && currentLanguageVersion < 21) {
excludes = ['**/java21/*.java']
}

if (21 <= currentLanguageVersion ) {
includes = ['**/java/java21/*.java']
excludes = ['**/java/JavaInputAstVisitor.java']
}
}
}


tasks.withType(Test).configureEach {
jvmArgs = jvmArgList
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* (c) Copyright 2024 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.javaformat.java.java21;

public class Java21InputAstVisitor {

public static void main(String[] args) {

Thread.startVirtualThread(() -> {
try {
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
});
}
}