Reputation: 163
I keep gettring build error saing that I'm using a preview feature (switch expressions):
Service.java:28: error: patterns in switch statements are a preview feature and are disabled by default.
case CalssA sr -> sr.getMeterReadings();
^
(use --enable-preview to enable patterns in switch statements)
I clearly said in build.gradle that I want to use Java 17. Switch expression were released in Java 14.
Here are my gradle.properties
, settings.gradle
, and build.gradle
:
quarkusPluginVersion=3.0.1.Final
quarkusPlatformArtifactId=quarkus-bom
quarkusPluginId=io.quarkus
quarkusPlatformGroupId=io.quarkus.platform
quarkusPlatformVersion=3.0.1.Final
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
mavenLocal()
}
plugins {
id "${quarkusPluginId}" version "${quarkusPluginVersion}"
}
}
rootProject.name='upc'
buildscript {
repositories {
mavenCentral()
gradlePluginPortal()
mavenLocal()
}
dependencies {
classpath 'com.h2database:h2:1.4.197'
}
}
plugins {
id 'java'
id 'io.quarkus'
id 'org.flywaydb.flyway' version '9.8.1'
}
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
def lombok_version = '1.18.26'
def map_struct_version = '1.5.5.Final'
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
implementation 'io.quarkus:quarkus-resteasy-reactive-qute'
implementation 'io.quarkus:quarkus-resteasy-reactive'
implementation 'io.quarkus:quarkus-resteasy-reactive-jackson'
implementation 'io.quarkus:quarkus-arc'
implementation 'io.quarkus:quarkus-flyway'
implementation 'io.quarkus:quarkus-hibernate-validator'
implementation 'io.quarkiverse.jdbc:quarkus-jdbc-sqlite:3.0.5'
implementation 'io.quarkiverse.mybatis:quarkus-mybatis:2.0.0'
implementation 'org.jboss.logging:jboss-logging'
implementation "org.mapstruct:mapstruct:${map_struct_version}"
implementation 'com.google.guava:guava:31.1-jre'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-guava:2.14.2'
compileOnly "org.projectlombok:lombok:${lombok_version}"
annotationProcessor "org.projectlombok:lombok:${lombok_version}"
annotationProcessor "org.mapstruct:mapstruct-processor:${map_struct_version}"
testCompileOnly "org.projectlombok:lombok:${lombok_version}"
testAnnotationProcessor "org.projectlombok:lombok:${lombok_version}"
testAnnotationProcessor "org.mapstruct:mapstruct-processor:${map_struct_version}"
testImplementation 'io.quarkus:quarkus-junit5'
testImplementation 'io.rest-assured:rest-assured'
}
group 'org.acanthite'
version '0.1'
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
test {
systemProperty 'java.util.logging.manager', 'org.jboss.logmanager.LogManager'
}
compileJava {
options.encoding = 'UTF-8'
options.compilerArgs += [
'-parameters',
'-Amapstruct.defaultComponentModel=cdi',
'-Amapstruct.defaultInjectionStrategy=constructor'
]
}
compileTestJava {
options.encoding = 'UTF-8'
options.compilerArgs += [
'-parameters',
'-Amapstruct.defaultComponentModel=cdi',
'-Amapstruct.defaultInjectionStrategy=constructor'
]
}
Here are IDEA settings for project:
What am I doing wrong? Is there any other place I need to specify Java version?
Upvotes: 2
Views: 554
Reputation: 163
I've figured out what's wrong.
Gradle and quarkus are fine and work perfectly.
The problem is that I'm not using switch expressions
but switch pattern matching
, which looks similar, but is a totally different thing. It is a preview feature in Java 17. Nevertheless, there is a compiler flag --enable-preview
which somehow works for non-test builds, but fails when running tests. See this issue: https://github.com/quarkusio/quarkus/issues/10472
Upvotes: 1