]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-14951 Scanners require Java 11
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 12 May 2020 11:52:39 +0000 (13:52 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 9 Jun 2021 20:03:05 +0000 (20:03 +0000)
23 files changed:
build.gradle
plugins/sonar-xoo-plugin/build.gradle
server/sonar-ce/src/main/java/org/sonar/ce/container/CePluginRepository.java
server/sonar-main/src/main/java/org/sonar/application/command/CeJvmOptions.java
server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java
server/sonar-main/src/main/java/org/sonar/application/command/JavaVersion.java [deleted file]
server/sonar-main/src/main/java/org/sonar/application/command/WebJvmOptions.java
server/sonar-main/src/test/java/org/sonar/application/command/CeJvmOptionsTest.java
server/sonar-main/src/test/java/org/sonar/application/command/CommandFactoryImplTest.java
server/sonar-main/src/test/java/org/sonar/application/command/WebJvmOptionsTest.java
server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java
server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java
sonar-application/src/main/java/org/sonar/application/App.java
sonar-check-api/build.gradle
sonar-core/build.gradle
sonar-markdown/build.gradle
sonar-plugin-api-impl/build.gradle
sonar-plugin-api/build.gradle
sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectInfo.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalContainer.java
sonar-scanner-protocol/build.gradle
sonar-testing-harness/build.gradle
sonar-ws/build.gradle

index 874b93c60c445889848b5641462c2be4a0d5d2b3..9a738e93b229eb93beac2a428f5525a9d603b7c1 100644 (file)
@@ -164,9 +164,6 @@ subprojects {
   apply plugin: 'idea'
   apply plugin: 'signing'
 
-  sourceCompatibility = 1.8
-  targetCompatibility = 1.8
-
   // do not deploy to Artifactory by default
   artifactoryPublish.skip = true
 
@@ -177,8 +174,74 @@ subprojects {
 
   ext {
     protobufVersion = '3.11.4'
+
+    // define a method which can be called by project to change Java version to compile to
+    configureCompileJavaToVersion = { javaVersion ->
+      if ( javaVersion != 11 & javaVersion != 8) {
+        throw new InvalidUserDataException("Only Java 8 and 11 are supported")
+      }
+      if ( javaVersion == 8 ) {
+        println "Configuring project ${project.name} to compile to Java ${javaVersion}"
+
+        if (!project.hasProperty('skipJava8Checks')) {
+          task ensureDependenciesRunOnJava8(dependsOn: [configurations.compileClasspath]) {
+            ext.readJavaMajorVersion = { classFile ->
+              classFile.withDataInputStream({ d ->
+                if (d.skip(7) == 7) {
+                  // read the version of the class file
+                  d.read()
+                } else {
+                  throw new GradleException("Could not read major version from $classFile")
+                }
+              })
+            }
+
+            doLast {
+              [configurations.compileClasspath].each { config ->
+                config.resolvedConfiguration.files
+                  .findAll({ f -> f.name.endsWith("jar") })
+                  .each { jarFile ->
+                    def onlyJava8 = true
+                    zipTree(jarFile)
+                      .matching({
+                        include "**/*.class"
+                        // multi-release jar files were introduced with Java 9 => contains only classes targeting Java 9+
+                        exclude "META-INF/versions/**"
+                        // ignore module-info existing in some archives for Java 9 forward compatibility
+                        exclude "module-info.class"
+                      })
+                      .files
+                      .each { classFile ->
+                        int javaMajorVersion = readJavaMajorVersion(classFile)
+                        if (javaMajorVersion > 52) {
+                          println "$classFile has been compiled to a more recent version of Java than 8 (java8=52, java11=55, actual=$javaMajorVersion)"
+                          onlyJava8 = false
+                        }
+                      }
+                    if (!onlyJava8) {
+                      throw new GradleException("Dependency ${jarFile} in configuration ${config.name} contains class file(s) compiled to a Java version > Java 8 (see logs for details)")
+                    }
+                  }
+              }
+            }
+          }
+
+          compileJava.dependsOn ensureDependenciesRunOnJava8
+        }
+      }
+
+      sourceCompatibility = javaVersion
+      targetCompatibility = javaVersion
+
+      tasks.withType(JavaCompile) {
+        options.compilerArgs.addAll(['--release', javaVersion + ''])
+        options.encoding = 'UTF-8'
+      }
+    }
   }
 
+  configureCompileJavaToVersion 11
+
   sonarqube {
     properties {
       property 'sonar.moduleKey', project.group + ':' + project.name
@@ -367,11 +430,6 @@ subprojects {
     exclude group: 'javax.mail', module: 'mail'
   }
 
-  tasks.withType(JavaCompile) {
-    options.compilerArgs.addAll(['--release', '8'])
-    options.encoding = 'UTF-8'
-  }
-
   tasks.withType(Javadoc) {
     options.addStringOption('Xdoclint:none', '-quiet')
     options.encoding = 'UTF-8'
index df25e2a4593f392482ee7d19a54f259716fbbb3d..b4bb30a3c1170a143fa81302ae982c97d29a1988 100644 (file)
@@ -2,6 +2,8 @@ configurations {
   testCompile.extendsFrom(compileOnly)
 }
 
+configureCompileJavaToVersion 8
+
 dependencies {
   compile 'com.google.guava:guava'
   compile 'commons-io:commons-io'
index ae22d5ddb3ea02266bb131cbbfa3db57ae1501d4..38da7d20514f309b0b93933b13bed66e02cf50ae 100644 (file)
  */
 package org.sonar.ce.container;
 
-import com.google.common.collect.ImmutableList;
 import java.io.File;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.Collectors;
 import org.apache.commons.io.FileUtils;
@@ -100,7 +100,7 @@ public class CePluginRepository implements PluginRepository, Startable {
   @Override
   public Collection<PluginInfo> getPluginInfos() {
     checkState(started.get(), NOT_STARTED_YET);
-    return ImmutableList.copyOf(pluginInfosByKeys.values());
+    return Set.copyOf(pluginInfosByKeys.values());
   }
 
   @Override
index 3490d66e0336497f43b1de5bd82812bbef6669dd..9896319fe15e9191a179a4888dca2c815a1e98ba 100644 (file)
@@ -25,21 +25,18 @@ import java.util.Map;
 
 public class CeJvmOptions extends JvmOptions<CeJvmOptions> {
 
-  public CeJvmOptions(File tmpDir, JavaVersion javaVersion) {
-    super(mandatoryOptions(tmpDir, javaVersion));
+  public CeJvmOptions(File tmpDir) {
+    super(mandatoryOptions(tmpDir));
   }
 
-  private static Map<String, String> mandatoryOptions(File tmpDir, JavaVersion javaVersion) {
+  private static Map<String, String> mandatoryOptions(File tmpDir) {
     Map<String, String> res = new LinkedHashMap<>(3);
     res.put("-Djava.awt.headless=", "true");
     res.put("-Dfile.encoding=", "UTF-8");
     res.put("-Djava.io.tmpdir=", tmpDir.getAbsolutePath());
     res.put("-XX:-OmitStackTraceInFastThrow", "");
-
-    if (javaVersion.isAtLeastJava11()) {
-      // avoid illegal reflective access operations done by MyBatis
-      res.put("--add-opens=java.base/java.util=ALL-UNNAMED", "");
-    }
+    // avoid illegal reflective access operations done by MyBatis
+    res.put("--add-opens=java.base/java.util=ALL-UNNAMED", "");
     return res;
   }
 }
index 9bd07d512e6a350dccbc318879f5cbc4b7fc6189..b51d2a69e6f2dcbf217833728ed348d721b70474 100644 (file)
@@ -75,13 +75,11 @@ public class CommandFactoryImpl implements CommandFactory {
   private final Props props;
   private final File tempDir;
   private final System2 system2;
-  private final JavaVersion javaVersion;
 
-  public CommandFactoryImpl(Props props, File tempDir, System2 system2, JavaVersion javaVersion) {
+  public CommandFactoryImpl(Props props, File tempDir, System2 system2) {
     this.props = props;
     this.tempDir = tempDir;
     this.system2 = system2;
-    this.javaVersion = javaVersion;
     String javaToolOptions = system2.getenv(ENV_VAR_JAVA_TOOL_OPTIONS);
     if (javaToolOptions != null && !javaToolOptions.trim().isEmpty()) {
       LoggerFactory.getLogger(CommandFactoryImpl.class)
@@ -155,7 +153,7 @@ public class CommandFactoryImpl implements CommandFactory {
   public JavaCommand createWebCommand(boolean leader) {
     File homeDir = props.nonNullValueAsFile(PATH_HOME.getKey());
 
-    WebJvmOptions jvmOptions = new WebJvmOptions(tempDir, javaVersion)
+    WebJvmOptions jvmOptions = new WebJvmOptions(tempDir)
       .addFromMandatoryProperty(props, WEB_JAVA_OPTS.getKey())
       .addFromMandatoryProperty(props, WEB_JAVA_ADDITIONAL_OPTS.getKey());
     addProxyJvmOptions(jvmOptions);
@@ -182,7 +180,7 @@ public class CommandFactoryImpl implements CommandFactory {
   public JavaCommand createCeCommand() {
     File homeDir = props.nonNullValueAsFile(PATH_HOME.getKey());
 
-    CeJvmOptions jvmOptions = new CeJvmOptions(tempDir, javaVersion)
+    CeJvmOptions jvmOptions = new CeJvmOptions(tempDir)
       .addFromMandatoryProperty(props, CE_JAVA_OPTS.getKey())
       .addFromMandatoryProperty(props, CE_JAVA_ADDITIONAL_OPTS.getKey());
     addProxyJvmOptions(jvmOptions);
diff --git a/server/sonar-main/src/main/java/org/sonar/application/command/JavaVersion.java b/server/sonar-main/src/main/java/org/sonar/application/command/JavaVersion.java
deleted file mode 100644 (file)
index b38df59..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2021 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.application.command;
-
-public class JavaVersion {
-  public static final JavaVersion INSTANCE = new JavaVersion();
-
-  public boolean isAtLeastJava11() {
-    try {
-      String.class.getMethod("isBlank");
-      return true;
-    } catch (NoSuchMethodException e) {
-      return false;
-    }
-  }
-}
index 33ac1ef56ba1935cc0d9834602a8a56027eac57a..e5a7ea1afed1180530954d6b75cf98a3be5cff10 100644 (file)
@@ -24,26 +24,24 @@ import java.util.LinkedHashMap;
 import java.util.Map;
 
 public class WebJvmOptions extends JvmOptions<WebJvmOptions> {
-  public WebJvmOptions(File tmpDir, JavaVersion javaVersion) {
-    super(mandatoryOptions(tmpDir, javaVersion));
+  public WebJvmOptions(File tmpDir) {
+    super(mandatoryOptions(tmpDir));
   }
 
-  private static Map<String, String> mandatoryOptions(File tmpDir, JavaVersion javaVersion) {
+  private static Map<String, String> mandatoryOptions(File tmpDir) {
     Map<String, String> res = new LinkedHashMap<>(3);
     res.put("-Djava.awt.headless=", "true");
     res.put("-Dfile.encoding=", "UTF-8");
     res.put("-Djava.io.tmpdir=", tmpDir.getAbsolutePath());
     res.put("-XX:-OmitStackTraceInFastThrow", "");
 
-    if (javaVersion.isAtLeastJava11()) {
-      // avoid illegal reflective access operations done by MyBatis
-      res.put("--add-opens=java.base/java.util=ALL-UNNAMED", "");
+    // avoid illegal reflective access operations done by MyBatis
+    res.put("--add-opens=java.base/java.util=ALL-UNNAMED", "");
 
-      // avoid illegal reflective access operations done by Tomcat
-      res.put("--add-opens=java.base/java.lang=ALL-UNNAMED", "");
-      res.put("--add-opens=java.base/java.io=ALL-UNNAMED", "");
-      res.put("--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED", "");
-    }
+    // avoid illegal reflective access operations done by Tomcat
+    res.put("--add-opens=java.base/java.lang=ALL-UNNAMED", "");
+    res.put("--add-opens=java.base/java.io=ALL-UNNAMED", "");
+    res.put("--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED", "");
     return res;
   }
 }
index 853929f1f6c617508cef0fbccbfd7bc96c1c1d6b..db4bb86ef153707c134a271920b8117128cc4b45 100644 (file)
@@ -27,15 +27,12 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 public class CeJvmOptionsTest {
   @Rule
   public TemporaryFolder temporaryFolder = new TemporaryFolder();
 
   private File tmpDir;
-  private JavaVersion javaVersion = mock(JavaVersion.class);
   private CeJvmOptions underTest;
 
   @Before
@@ -44,17 +41,8 @@ public class CeJvmOptionsTest {
   }
 
   @Test
-  public void constructor_sets_mandatory_JVM_options_before_java11() {
-    when(javaVersion.isAtLeastJava11()).thenReturn(false);
-    underTest = new CeJvmOptions(tmpDir, javaVersion);
-    assertThat(underTest.getAll()).containsExactly(
-      "-Djava.awt.headless=true", "-Dfile.encoding=UTF-8", "-Djava.io.tmpdir=" + tmpDir.getAbsolutePath(), "-XX:-OmitStackTraceInFastThrow");
-  }
-
-  @Test
-  public void constructor_sets_mandatory_JVM_options_for_java11() {
-    when(javaVersion.isAtLeastJava11()).thenReturn(true);
-    underTest = new CeJvmOptions(tmpDir, javaVersion);
+  public void constructor_sets_mandatory_JVM_options() {
+    underTest = new CeJvmOptions(tmpDir);
     assertThat(underTest.getAll()).containsExactly(
       "-Djava.awt.headless=true", "-Dfile.encoding=UTF-8", "-Djava.io.tmpdir=" + tmpDir.getAbsolutePath(), "-XX:-OmitStackTraceInFastThrow",
       "--add-opens=java.base/java.util=ALL-UNNAMED");
index f8d7029008a71e77f55accaa67eab0d000ca4713..ddcf1cad5011db36d08468ebb7e4c3812a27b8f9 100644 (file)
@@ -53,7 +53,6 @@ public class CommandFactoryImplTest {
   public TemporaryFolder temp = new TemporaryFolder();
 
   private System2 system2 = Mockito.mock(System2.class);
-  private JavaVersion javaVersion = Mockito.mock(JavaVersion.class);
   private File homeDir;
   private File tempDir;
   private File logsDir;
@@ -77,7 +76,7 @@ public class CommandFactoryImplTest {
   public void constructor_logs_no_warning_if_env_variable_JAVA_TOOL_OPTIONS_is_not_set() {
     attachMemoryAppenderToLoggerOf(CommandFactoryImpl.class);
 
-    new CommandFactoryImpl(new Props(new Properties()), tempDir, system2, javaVersion);
+    new CommandFactoryImpl(new Props(new Properties()), tempDir, system2);
 
     assertThat(listAppender.getLogs()).isEmpty();
   }
@@ -87,7 +86,7 @@ public class CommandFactoryImplTest {
     when(system2.getenv("JAVA_TOOL_OPTIONS")).thenReturn("sds");
     attachMemoryAppenderToLoggerOf(CommandFactoryImpl.class);
 
-    new CommandFactoryImpl(new Props(new Properties()), tempDir, system2, javaVersion);
+    new CommandFactoryImpl(new Props(new Properties()), tempDir, system2);
 
     assertThat(listAppender.getLogs())
       .extracting(ILoggingEvent::getMessage)
@@ -101,7 +100,7 @@ public class CommandFactoryImplTest {
     when(system2.getenv("ES_JAVA_OPTS")).thenReturn("xyz");
     attachMemoryAppenderToLoggerOf(CommandFactoryImpl.class);
 
-    new CommandFactoryImpl(new Props(new Properties()), tempDir, system2, javaVersion);
+    new CommandFactoryImpl(new Props(new Properties()), tempDir, system2);
 
     assertThat(listAppender.getLogs())
       .extracting(ILoggingEvent::getMessage)
@@ -321,7 +320,7 @@ public class CommandFactoryImplTest {
     ServiceLoaderWrapper serviceLoaderWrapper = mock(ServiceLoaderWrapper.class);
     when(serviceLoaderWrapper.load()).thenReturn(ImmutableSet.of());
     new ProcessProperties(serviceLoaderWrapper).completeDefaults(props);
-    return new CommandFactoryImpl(props, tempDir, system2, javaVersion);
+    return new CommandFactoryImpl(props, tempDir, system2);
   }
 
   private <T> void attachMemoryAppenderToLoggerOf(Class<T> loggerClass) {
index 4d966f7641eae24129c17fff0fc9688e4c42deab..e4f9da4b96f068a1e48b2bd918ed45c92a239781 100644 (file)
@@ -27,15 +27,12 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 public class WebJvmOptionsTest {
   @Rule
   public TemporaryFolder temporaryFolder = new TemporaryFolder();
 
   private File tmpDir;
-  private JavaVersion javaVersion = mock(JavaVersion.class);
   private WebJvmOptions underTest;
 
   @Before
@@ -44,17 +41,8 @@ public class WebJvmOptionsTest {
   }
 
   @Test
-  public void constructor_sets_mandatory_JVM_options_before_java11() {
-    when(javaVersion.isAtLeastJava11()).thenReturn(false);
-    underTest = new WebJvmOptions(tmpDir, javaVersion);
-    assertThat(underTest.getAll()).containsExactly(
-      "-Djava.awt.headless=true", "-Dfile.encoding=UTF-8", "-Djava.io.tmpdir=" + tmpDir.getAbsolutePath(), "-XX:-OmitStackTraceInFastThrow");
-  }
-
-  @Test
-  public void constructor_sets_mandatory_JVM_options_for_java11() {
-    when(javaVersion.isAtLeastJava11()).thenReturn(true);
-    underTest = new WebJvmOptions(tmpDir, javaVersion);
+  public void constructor_sets_mandatory_JVM_options() {
+    underTest = new WebJvmOptions(tmpDir);
 
     assertThat(underTest.getAll()).containsExactly(
       "-Djava.awt.headless=true", "-Dfile.encoding=UTF-8", "-Djava.io.tmpdir=" + tmpDir.getAbsolutePath(), "-XX:-OmitStackTraceInFastThrow",
index e7813b984bd42906aac05a43b0485e23bbf7ef8c..39eee326b0c4cd584f8125f7fa39193b6dafa909 100644 (file)
@@ -176,7 +176,7 @@ public class EmailNotificationChannel extends NotificationChannel {
     }
 
     return (int) deliveries.stream()
-      .filter(t -> !t.getRecipientEmail().trim().isEmpty())
+      .filter(t -> !t.getRecipientEmail().isBlank())
       .map(t -> {
         EmailMessage emailMessage = format(t.getNotification());
         if (emailMessage != null) {
index 86b5c3148c5e73cb33e2845a1e5e71a49ed955ae..ce0fc6e48e0e4df75b593942462ea12bf798c8f1 100644 (file)
@@ -225,7 +225,7 @@ public class RegisterRules implements Startable {
         .filter(Objects::nonNull)
         .findFirst();
       // may occur in case of plugin downgrade
-      if (!res.isPresent()) {
+      if (res.isEmpty()) {
         return Optional.ofNullable(dbRulesByDbDeprecatedKey.get(ruleKey));
       }
       return res;
index aaea1090f12fc64c7f0021496c3b67ad9955ee4e..bd4b19204e3d42cf0bba863aedaa195375bb084f 100644 (file)
  */
 package org.sonar.application;
 
-import org.sonar.api.SonarEdition;
-import org.sonar.api.internal.MetadataLoader;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.application.command.CommandFactory;
 import org.sonar.application.command.CommandFactoryImpl;
-import org.sonar.application.command.JavaVersion;
 import org.sonar.application.config.AppSettings;
 import org.sonar.application.config.AppSettingsLoader;
 import org.sonar.application.config.AppSettingsLoaderImpl;
@@ -32,19 +29,14 @@ import org.sonar.core.extension.ServiceLoaderWrapper;
 import org.sonar.process.System2;
 import org.sonar.process.SystemExit;
 
-import static com.google.common.base.Preconditions.checkState;
 import static org.sonar.application.config.SonarQubeVersionHelper.getSonarqubeVersion;
 import static org.sonar.process.ProcessProperties.Property.CLUSTER_NAME;
 
 public class App {
 
   private final SystemExit systemExit = new SystemExit();
-  private final JavaVersion javaVersion;
   private StopRequestWatcher stopRequestWatcher = null;
   private StopRequestWatcher hardStopRequestWatcher = null;
-  public App(JavaVersion javaVersion) {
-    this.javaVersion = javaVersion;
-  }
 
   public void start(String[] cliArguments) {
     AppSettingsLoader settingsLoader = new AppSettingsLoaderImpl(System2.INSTANCE, cliArguments, new ServiceLoaderWrapper());
@@ -53,14 +45,13 @@ public class App {
     AppLogging logging = new AppLogging(settings);
     logging.configure();
     AppFileSystem fileSystem = new AppFileSystem(settings);
-    checkJavaVersion();
 
     try (AppState appState = new AppStateFactory(settings).create()) {
       appState.registerSonarQubeVersion(getSonarqubeVersion());
       appState.registerClusterName(settings.getProps().nonNullValue(CLUSTER_NAME.getKey()));
       AppReloader appReloader = new AppReloaderImpl(settingsLoader, fileSystem, appState, logging);
       fileSystem.reset();
-      CommandFactory commandFactory = new CommandFactoryImpl(settings.getProps(), fileSystem.getTempDir(), System2.INSTANCE, JavaVersion.INSTANCE);
+      CommandFactory commandFactory = new CommandFactoryImpl(settings.getProps(), fileSystem.getTempDir(), System2.INSTANCE);
 
       try (ProcessLauncher processLauncher = new ProcessLauncherImpl(fileSystem.getTempDir())) {
         Scheduler scheduler = new SchedulerImpl(settings, appReloader, commandFactory, processLauncher, appState);
@@ -86,15 +77,8 @@ public class App {
     systemExit.exit(0);
   }
 
-  private void checkJavaVersion() {
-    if (MetadataLoader.loadEdition(org.sonar.api.utils.System2.INSTANCE) == SonarEdition.SONARCLOUD) {
-      return;
-    }
-    checkState(javaVersion.isAtLeastJava11(), "SonarQube requires Java 11 to run");
-  }
-
   public static void main(String[] args) throws Exception {
-    new App(JavaVersion.INSTANCE).start(args);
+    new App().start(args);
   }
 
   private class ShutdownHook extends Thread {
index f76bc07f842f4878da1dbc81d1c89fcc0772b245..bf0f33e4f2953a37974dda2433885377939c5eb6 100644 (file)
@@ -4,6 +4,8 @@ sonarqube {
   }
 }
 
+configureCompileJavaToVersion 8
+
 dependencies {
   compileOnly 'com.google.code.findbugs:jsr305'
 }
index 7a44963f1c3343f8f4ae90750fad0ab2e97c929f..3b658b278c9a426bfa90bd0137f3db5d1d81956e 100644 (file)
@@ -4,6 +4,8 @@ sonarqube {
   }
 }
 
+configureCompileJavaToVersion 8
+
 dependencies {
   // please keep list ordered
 
index 16e8e834cdc5976a8e1f5c9977432319f5475a81..f75aae381bf46571f6b5ba01f481fc3470861df2 100644 (file)
@@ -4,6 +4,8 @@ sonarqube {
   }
 }
 
+configureCompileJavaToVersion 8
+
 dependencies {
   // please keep list ordered
 
index ee9930a295ddeaddd1fe0ff0cd407fd6c2aaf220..303fa2f1549b850469eb6b8a9f4c26fe810c387a 100644 (file)
@@ -4,6 +4,8 @@ sonarqube {
   }
 }
 
+configureCompileJavaToVersion 8
+
 dependencies {
   // please keep the list grouped by configuration and ordered by name
 
index 04612e584274c150141919db6dc60a9ba16d117b..8cdf7778f70076dcae292b1d2c5062a6a5d69b01 100644 (file)
@@ -4,6 +4,8 @@ sonarqube {
   }
 }
 
+configureCompileJavaToVersion 8
+
 apply plugin: 'com.github.johnrengelman.shadow'
 
 dependencies {
index bd1028670f980ba9db69c5246cffca2813b3e8e8..dea7bdfc6e156d37e3d5be2a216291d5606b8b4e 100644 (file)
@@ -66,7 +66,7 @@ public class ProjectInfo implements Startable {
 
   private Date loadAnalysisDate() {
     Optional<String> value = settings.get(CoreProperties.PROJECT_DATE_PROPERTY);
-    if (!value.isPresent()) {
+    if (value.isEmpty()) {
       return Date.from(clock.instant());
     }
     try {
index e8aee0067b95f30c43fc88011d9478c176db81ac..dfc5047dd190ef21c4cba03e40e3e6dfafba6559 100644 (file)
@@ -31,7 +31,6 @@ import org.sonar.api.SonarQubeVersion;
 import org.sonar.api.SonarRuntime;
 import org.sonar.api.internal.MetadataLoader;
 import org.sonar.api.internal.SonarRuntimeImpl;
-import org.sonar.api.notifications.AnalysisWarnings;
 import org.sonar.api.utils.MessageException;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.UriReader;
@@ -83,23 +82,10 @@ public class GlobalContainer extends ComponentContainer {
     addBootstrapComponents();
   }
 
-  private static void checkJavaVersion(AnalysisWarnings analysisWarnings) {
-    try {
-      String.class.getMethod("isBlank");
-    } catch (NoSuchMethodException e) {
-      LOG.warn("SonarScanner will require Java 11 to run, starting in SonarQube 9.x");
-      analysisWarnings.addUnique("SonarScanner will require Java 11 to run, starting in SonarQube 9.x. Please upgrade the version of Java that executes the scanner and " + 
-          "refer to <a href=\"/documentation/analysis/analysis-with-java-11/\" target=\"_blank\">the documentation</a> if needed.");
-    }
-  }
-
   private void addBootstrapComponents() {
     Version apiVersion = MetadataLoader.loadVersion(System2.INSTANCE);
     SonarEdition edition = MetadataLoader.loadEdition(System2.INSTANCE);
     DefaultAnalysisWarnings analysisWarnings = new DefaultAnalysisWarnings(System2.INSTANCE);
-    if (edition != SonarEdition.SONARCLOUD) {
-      checkJavaVersion(analysisWarnings);
-    }
     LOG.debug("{} {}", edition.getLabel(), apiVersion);
     add(
       // plugins
index 805cedb6d12db4174941a7c03bfaa9ea70c023a8..f89669bd22284b6c2f5511542aeaa43782d4919b 100644 (file)
@@ -5,6 +5,8 @@ sonarqube {
   }
 }
 
+configureCompileJavaToVersion 8
+
 dependencies {
   // please keep the list ordered
   compile 'com.google.code.gson:gson'
index 2138f193b85455b48f02dd129152b87da80a972a..80da028df67fa514fa059f5485ceb2a1a7d0d36e 100644 (file)
@@ -4,6 +4,8 @@ sonarqube {
   }
 }
 
+configureCompileJavaToVersion 8
+
 dependencies {
   // please keep list ordered
 
index a1640ab28b0a1c47d84ef08bbbf5f1c74142d53c..bfb707e01e707b143671521729ddd4cfd81ab76b 100644 (file)
@@ -5,6 +5,8 @@ sonarqube {
   }
 }
 
+configureCompileJavaToVersion 8
+
 configurations {
   testCompile.extendsFrom(compileOnly)
 }