Skip to content

Commit

Permalink
Merge pull request #16426 from mshima/skip_ci-java_17
Browse files Browse the repository at this point in the history
Consolidate java supported versions and add support to java 17.
  • Loading branch information
DanielFran authored Oct 9, 2021
2 parents 2b031aa + 38f2561 commit f7c28ae
Show file tree
Hide file tree
Showing 16 changed files with 230 additions and 49 deletions.
2 changes: 2 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ runs:
# https://github.com/actions/virtual-environments/issues/1499#issuecomment-689467080
echo "MAVEN_OPTS=-Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.httpconnectionManager.ttlSeconds=120" >> $GITHUB_ENV
# Use java backward compatible locale values https://bugs.openjdk.java.net/browse/JDK-8267069
echo "java.locale.useOldISOCodes=true" >> $GITHUB_ENV
echo "::set-output name=application-path::${{inputs.application-path}}"
echo "::set-output name=date::$(/bin/date -u "+%Y%m%d")"
Expand Down
3 changes: 3 additions & 0 deletions generators/azure-app-service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ module.exports = class extends BaseBlueprintGenerator {
this.azureAppInsightsInstrumentationKey = '';
this.azureGroupId = '';
},
loadConstants() {
this.JAVA_VERSION = constants.JAVA_VERSION;
},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
- name: Set up JDK <%= JAVA_VERSION %>
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: 11
java-version: <%= JAVA_VERSION %>
- name: Cache Maven archetypes
uses: actions/cache@v1
with:
Expand Down
3 changes: 3 additions & 0 deletions generators/azure-spring-cloud/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ module.exports = class extends BaseBlueprintGenerator {
this.azureSpringCloudAppName = this.config.get('azureSpringCloudAppName');
this.azureSpringCloudDeploymentType = this.config.get('azureSpringCloudDeploymentType');
},
loadConstants() {
this.JAVA_VERSION = constants.JAVA_VERSION;
},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
- name: Set up JDK <%= JAVA_VERSION %>
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: 11
java-version: <%= JAVA_VERSION %>
- name: Cache Maven archetypes
uses: actions/cache@v1
with:
Expand Down
1 change: 1 addition & 0 deletions generators/ci-cd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ module.exports = class extends BaseBlueprintGenerator {
this.SERVER_MAIN_RES_DIR = constants.SERVER_MAIN_RES_DIR;
this.DOCKER_JENKINS = constants.DOCKER_JENKINS;
this.ANGULAR = constants.SUPPORTED_CLIENT_FRAMEWORKS.ANGULAR;
this.JAVA_VERSION = constants.JAVA_VERSION;
},
};
}
Expand Down
2 changes: 1 addition & 1 deletion generators/ci-cd/templates/github-actions.yml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ if (!skipServer) { _%>
- uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '11.x'
java-version: <%= JAVA_VERSION %>
<%_ }
if (!skipClient) { _%>
- name: Install node.js packages
Expand Down
13 changes: 9 additions & 4 deletions generators/ci-cd/templates/travis.yml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ cache:
env:
global:
- NODE_VERSION=<%= NODE_VERSION %>
- JHI_JDK=<%= JAVA_VERSION %>
- SPRING_OUTPUT_ANSI_ENABLED=ALWAYS
- SPRING_JPA_SHOW_SQL=false
- JHI_DISABLE_WEBPACK_LOGS=true
Expand All @@ -47,13 +48,17 @@ env:
<%_ } _%>
before_install:
- |
if [[ $JHI_JDK = '8' ]]; then
echo '*** Using OpenJDK 8'
if [[ $JHI_JDK = '17' ]]; then
echo '*** Using OpenJDK 17'
sudo add-apt-repository ppa:openjdk-r/ppa -y
sudo apt-get update -q
sudo apt-get install -y openjdk-17-jdk -y
sudo update-java-alternatives -s java-1.17.0-openjdk-amd64
java -version
else
echo '*** Using OpenJDK 11 by default'
sudo add-apt-repository ppa:openjdk-r/ppa -y
sudo apt-get update -q
sudo apt-get install -y openjdk-11-jdk -y
sudo apt-get install -y openjdk-11-jdk
sudo update-java-alternatives -s java-1.11.0-openjdk-amd64
java -version
fi
Expand Down
22 changes: 7 additions & 15 deletions generators/generator-base-private.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,13 @@ const https = require('https');
const { reproducibleConfigForTests: projectNameReproducibleConfigForTests } = require('./project-name/config.cjs');
const packagejs = require('../package.json');
const jhipsterUtils = require('./utils');
const constants = require('./generator-constants');
const { JAVA_COMPATIBLE_VERSIONS, SERVER_TEST_SRC_DIR, SUPPORTED_CLIENT_FRAMEWORKS } = require('./generator-constants');
const { languageToJavaLanguage } = require('./utils');
const JSONToJDLEntityConverter = require('../jdl/converters/json-to-jdl-entity-converter');
const JSONToJDLOptionConverter = require('../jdl/converters/json-to-jdl-option-converter');
const { stringify } = require('../utils');

const SERVER_TEST_SRC_DIR = constants.SERVER_TEST_SRC_DIR;
const ANGULAR = constants.SUPPORTED_CLIENT_FRAMEWORKS.ANGULAR;
const REACT = constants.SUPPORTED_CLIENT_FRAMEWORKS.REACT;
const VUE = constants.SUPPORTED_CLIENT_FRAMEWORKS.VUE;
const { ANGULAR, REACT, VUE } = SUPPORTED_CLIENT_FRAMEWORKS;
const dbTypes = require('../jdl/jhipster/field-types');
const { REQUIRED } = require('../jdl/jhipster/validations');

Expand Down Expand Up @@ -809,17 +806,12 @@ module.exports = class JHipsterBasePrivateGenerator extends Generator {
this.warning('Java is not found on your computer.');
} else {
const javaVersion = stderr.match(/(?:java|openjdk) version "(.*)"/)[1];
if (
!javaVersion.match(new RegExp('16')) &&
!javaVersion.match(new RegExp('15')) &&
!javaVersion.match(new RegExp('14')) &&
!javaVersion.match(new RegExp('13')) &&
!javaVersion.match(new RegExp('12')) &&
!javaVersion.match(new RegExp('11')) &&
!javaVersion.match(new RegExp('1.8'.replace('.', '\\.')))
) {
if (!javaVersion.match(new RegExp(`(${JAVA_COMPATIBLE_VERSIONS.map(ver => `^${ver}`).join('|')})`))) {
const [latest, ...others] = JAVA_COMPATIBLE_VERSIONS.reverse();
this.warning(
`Java 8, 11, 12, 13, 14, 15 or 16 are not found on your computer. Your Java version is: ${chalk.yellow(javaVersion)}`
`Java ${others.reverse().join(', ')} or ${latest} are not found on your computer. Your Java version is: ${chalk.yellow(
javaVersion
)}`
);
}
}
Expand Down
9 changes: 7 additions & 2 deletions generators/generator-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const { ANGULAR_X, REACT, VUE } = require('../jdl/jhipster/client-framework-type
const commonPackageJson = require('./common/templates/package.json');

// Version of Java
const JAVA_VERSION = '11'; // Java version is forced to be 11. We keep the variable as it might be useful in the future.
const JAVA_VERSION = '11';
const JAVA_COMPATIBLE_VERSIONS = ['11', '12', '13', '14', '15', '16', '17'];

// Version of Node, NPM
const NODE_VERSION = '14.17.6';
Expand Down Expand Up @@ -247,10 +248,13 @@ const LANGUAGES = [
name: 'Indonesian',
dispName: 'Bahasa Indonesia',
/*
To fix a nasty bug in the JDK ("Indonesian Locale does not comply with ISO 639")
JDK <17 ("Indonesian Locale does not comply with ISO 639")
The locale is set to "in" for Indonesia
See https://bugs.openjdk.java.net/browse/JDK-6457127
And https://github.com/jhipster/generator-jhipster/issues/9494
Java 17 supports 'id' locale, for compatibility with java 11, we will keep legacy 'in' value while we support java 11.
When running with java 17 users must set 'java.locale.useOldISOCodes=true' environment variable.
See https://bugs.openjdk.java.net/browse/JDK-8267069.
*/
value: 'in',
localeId: 'id',
Expand Down Expand Up @@ -379,6 +383,7 @@ const constants = {
DOCKER_PROMETHEUS_ALERTMANAGER,
DOCKER_GRAFANA,
JAVA_VERSION,
JAVA_COMPATIBLE_VERSIONS,
KAFKA_VERSION,
GRADLE_VERSION,

Expand Down
2 changes: 1 addition & 1 deletion generators/java/constants.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const { MAVEN: BUILD_TOOL_MAVEN, MAVEN_DESCRIPTION, BUILD_DESTINATION_VALUE } =
const { GRADLE: BUILD_TOOL_GRADLE, GRADLE_DESCRIPTION } = require('../gradle/constants.cjs');

const JAVA_VERSION = '11';
const JAVA_COMPATIBLE_VERSIONS = ['1.8', '1.9', '10', '11', '12', '13', '14', '15', '16'];
const JAVA_COMPATIBLE_VERSIONS = ['11', '12', '13', '14', '15', '16', '17'];
const JAVA_APP_VERSION = '0.0.1-SNAPSHOT';
const JAVA_SOURCE_DIR = 'src/main/java/';
const JAVA_RESOURCE_DIR = 'src/main/resources/';
Expand Down
9 changes: 9 additions & 0 deletions generators/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ module.exports = class JHipsterServerGenerator extends BaseBlueprintGenerator {
this.DOCKER_COMPOSE_FORMAT_VERSION = constants.DOCKER_COMPOSE_FORMAT_VERSION;

this.JAVA_VERSION = constants.JAVA_VERSION;
this.JAVA_COMPATIBLE_VERSIONS = constants.JAVA_COMPATIBLE_VERSIONS;

this.NODE_VERSION = constants.NODE_VERSION;
this.NPM_VERSION = constants.NPM_VERSION;
Expand Down Expand Up @@ -595,6 +596,14 @@ module.exports = class JHipsterServerGenerator extends BaseBlueprintGenerator {
// Public API method used by the getter and also by Blueprints
_end() {
return {
checkLocaleValue() {
if (this.languages && this.languages.includes('in')) {
this.warning(
"For jdk 17 compatibility 'in' locale value should set 'java.locale.useOldISOCodes=true' environment variable. Refer to https://bugs.openjdk.java.net/browse/JDK-8267069"
);
}
},

end() {
this.log(chalk.green.bold('\nServer application generated successfully.\n'));

Expand Down
18 changes: 17 additions & 1 deletion generators/server/templates/build.gradle.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ description = ""

sourceCompatibility=<%= JAVA_VERSION %>
targetCompatibility=<%= JAVA_VERSION %>
assert System.properties["java.specification.version"] == "1.8" || "1.9" || "10" || "11" || "12" || "13" || "14" || "15" || "16" || "17"
assert System.properties["java.specification.version"] == <%- JAVA_COMPATIBLE_VERSIONS.map(ver => `"${ver}"`).join(' || '); %>

apply from: "gradle/docker.gradle"
apply from: "gradle/sonar.gradle"
Expand Down Expand Up @@ -127,6 +127,14 @@ test {
// see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
// ignoreFailures true
reports.html.enabled = false
<%_ if (reactive) { _%>
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_13)) {
jvmArgs += [
"-XX:+AllowRedefinitionToAddDeleteMethods"
]
}
<%_ } _%>
}

modernizer {
Expand Down Expand Up @@ -164,6 +172,14 @@ task integrationTest(type: Test) {
// see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
// ignoreFailures true
reports.html.enabled = false
<%_ if (reactive) { _%>
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_13)) {
jvmArgs += [
"-XX:+AllowRedefinitionToAddDeleteMethods"
]
}
<%_ } _%>
}
<%_ if (cucumberTests) { _%>
Expand Down
122 changes: 120 additions & 2 deletions generators/server/templates/pom.xml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -1379,8 +1379,8 @@
<version>[${maven.version},)</version>
</requireMavenVersion>
<requireJavaVersion>
<message>You are running an incompatible version of Java. JHipster supports JDK 8 to 17.</message>
<version>[1.8,18)</version>
<message>You are running an incompatible version of Java. JHipster supports JDK <%= JAVA_COMPATIBLE_VERSIONS[0] %> to <%= JAVA_COMPATIBLE_VERSIONS[JAVA_COMPATIBLE_VERSIONS.length -1] %>.</message>
<version><%= JAVA_COMPATIBLE_VERSIONS.map(version => parseInt(version)).map(version => `[${version},${version +1})`).join(',') %></version>
</requireJavaVersion>
</rules>
</configuration>
Expand Down Expand Up @@ -1430,6 +1430,7 @@
</execution>
</executions>
</plugin>
<%_ if (!reactive) { _%>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down Expand Up @@ -1473,6 +1474,7 @@
</execution>
</executions>
</plugin>
<%_ } _%>
<%_ if (enableSwaggerCodegen) { _%>
<plugin>
<!--
Expand Down Expand Up @@ -1999,6 +2001,122 @@
</pluginManagement>
</build>
</profile>
<%_ } _%>
<%_ if (reactive) { _%>
<profile>
<id>surefire-java13-</id>
<activation>
<jdk>(,13]</jdk>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<!-- Force alphabetical order to have a reproducible build -->
<runOrder>alphabetical</runOrder>
<excludes>
<exclude>**/*IT*</exclude>
<exclude>**/*IntTest*</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-failsafe-plugin.version}</version>
<configuration>
<!-- Due to spring-boot repackage, without adding this property test classes are not found
See https://github.com/spring-projects/spring-boot/issues/6254 -->
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<!-- Force alphabetical order to have a reproducible build -->
<runOrder>alphabetical</runOrder>
<includes>
<include>**/*IT*</include>
<include>**/*IntTest*</include>
</includes>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
<profile>
<id>surefire-java13+</id>
<activation>
<jdk>(13,]</jdk>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<!-- Force alphabetical order to have a reproducible build -->
<runOrder>alphabetical</runOrder>
<excludes>
<exclude>**/*IT*</exclude>
<exclude>**/*IntTest*</exclude>
</excludes>
<!-- Fix tests at java 13+ https://github.com/reactor/BlockHound/issues/33 -->
<argLine>-XX:+AllowRedefinitionToAddDeleteMethods</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-failsafe-plugin.version}</version>
<configuration>
<!-- Due to spring-boot repackage, without adding this property test classes are not found
See https://github.com/spring-projects/spring-boot/issues/6254 -->
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<!-- Force alphabetical order to have a reproducible build -->
<runOrder>alphabetical</runOrder>
<includes>
<include>**/*IT*</include>
<include>**/*IntTest*</include>
</includes>
<!-- Fix tests at java 13+ https://github.com/reactor/BlockHound/issues/33 -->
<argLine>-XX:+AllowRedefinitionToAddDeleteMethods</argLine>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
<%_ } _%>
<!-- jhipster-needle-maven-add-profile -->
</profiles>
Expand Down
Loading

0 comments on commit f7c28ae

Please sign in to comment.