From e1f9f35d61521652abcb65d29cd3637ed4a344a1 Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Fri, 19 Mar 2021 16:49:16 +0700 Subject: [PATCH] Proper JPMS module --- build.gradle | 49 ++++++++++++++++++---- gradle.properties | 5 ++- gradle/wrapper/gradle-wrapper.properties | 18 +++++++- module-info/build.gradle | 17 ++++++++ module-info/src/main/java/module-info.java | 20 +++++++++ settings.gradle | 18 +++++++- 6 files changed, 116 insertions(+), 11 deletions(-) create mode 100644 module-info/build.gradle create mode 100644 module-info/src/main/java/module-info.java diff --git a/build.gradle b/build.gradle index 1742bd8..9116b63 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ /* - * Copyright 2000-2020 JetBrains s.r.o. + * Copyright 2000-2021 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,18 +47,54 @@ subprojects { project(':java5').archivesBaseName = 'annotations-java5' project(':java8').archivesBaseName = 'annotations' +def jdk5Home = System.getenv("JDK_5") +if (hasProperty("JDK_5")) { + jdk5Home = JDK_5 +} +if (jdk5Home == null) { + throw new GradleException('JDK_5 environment variable is not defined. It must point to any JDK that ' + + 'is capable to compile with Java 5 target (Any JDK version from 1.5 to 1.8)') +} + +configure(project(':module-info')) { + dependencies { + compile project(':common') + } + + compileJava { + // Without common sources, compiler complains that exported packages don't exist + source = [sourceSets.main.java, project(':common').sourceSets.main.java] + } + + task mainJar(type: Jar) { + } +} + configure([project(':java5'), project(':java8')]) { + dependencies { + compile project(':module-info') + } + task mainJar(type: Jar) { - manifest { - attributes('Automatic-Module-Name': 'org.jetbrains.' + archivesBaseName.replace('-', '_')) - } + into ("META-INF/versions/9", { + from (project(':module-info').sourceSets.main.output, { + // Skip extra files from common sources compiled with Java 9 target + include("module-info.class") + }) + }) + duplicatesStrategy = DuplicatesStrategy.FAIL } task sourceJar(type: Jar) { + into ("META-INF/versions/9", { + from project(':module-info').sourceSets.main.java + }) + duplicatesStrategy = DuplicatesStrategy.FAIL baseName = archivesBaseName + '-sources' } task javadocJar(type: Jar) { + duplicatesStrategy = DuplicatesStrategy.FAIL from javadoc } @@ -144,6 +180,8 @@ configure(project(':java5')) { } compileJava { + options.fork = true + options.forkOptions.executable = "$jdk5Home/bin/javac" dependsOn(generateSrc) source sourceSets.generated.java } @@ -163,9 +201,6 @@ configure(project(':java5')) { } configure(project(':java8')) { - dependencies { - compile project(':common') - } mainJar { from sourceSets.main.output diff --git a/gradle.properties b/gradle.properties index 35163ec..1f36d36 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # -# Copyright 2000-2020 JetBrains s.r.o. +# Copyright 2000-2021 JetBrains s.r.o. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,4 +14,5 @@ # limitations under the License. # -projectVersion=20.1.0 \ No newline at end of file +projectVersion=20.2.0 +#JDK_5= \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index be2a0db..2f3d235 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,22 @@ +# +# Copyright 2000-2021 JetBrains s.r.o. +# +# 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 +# +# https://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. +# + #Fri Feb 16 15:00:47 MSK 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-all.zip diff --git a/module-info/build.gradle b/module-info/build.gradle new file mode 100644 index 0000000..46444b6 --- /dev/null +++ b/module-info/build.gradle @@ -0,0 +1,17 @@ +/* + * Copyright 2000-2021 JetBrains s.r.o. + * + * 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 + * + * https://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. + */ + +sourceCompatibility = 1.9 diff --git a/module-info/src/main/java/module-info.java b/module-info/src/main/java/module-info.java new file mode 100644 index 0000000..b649ea1 --- /dev/null +++ b/module-info/src/main/java/module-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2000-2020 JetBrains s.r.o. + * + * 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 + * + * https://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. + */ +module org.jetbrains.annotations { + exports org.intellij.lang.annotations; + exports org.jetbrains.annotations; + requires java.desktop; +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 7774169..c4e6b4c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,19 @@ +/* + * Copyright 2000-2021 JetBrains s.r.o. + * + * 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 + * + * https://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. + */ + rootProject.name = 'annotations-parent' -include 'common', 'java5', 'java8' \ No newline at end of file +include 'common', 'java5', 'java8', 'module-info' \ No newline at end of file