Skip to content

Commit 932cf3d

Browse files
author
核桃
committed
Java8 jdk can be compile normally
Java9+Jakarta EE must be compile and package using java9+ jdk to support Multi-Release
1 parent 608c486 commit 932cf3d

File tree

2 files changed

+325
-4
lines changed

2 files changed

+325
-4
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ dependencies {
6868
<version>5.0.1</version>
6969
</dependency>
7070
```
71+
**NOTE:** If you use **Java9+ and Jakarta EE** you need use the version **6.0.0**
7172

7273
**Ivy and SBT**<br/>
7374
There have been reports of problems resolving some dependencies when using Ivy or SBT, for help resolving those issues see:<br/>

pom.xml

+324-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>org.gitlab4j</groupId>
88
<artifactId>gitlab4j-api</artifactId>
99
<packaging>jar</packaging>
10-
<version>5.1.0-SNAPSHOT</version>
10+
<version>6.0.0-SNAPSHOT</version>
1111
<name>GitLab4J-API - GitLab API Java Client</name>
1212
<description>GitLab4J-API (gitlab4j-api) provides a full featured Java client library for working with GitLab repositories and servers via the GitLab REST API.</description>
1313
<url>https://github.com/gitlab4j/gitlab4j-api</url>
@@ -71,6 +71,10 @@
7171
<gitlab.skip-docker-start>true</gitlab.skip-docker-start>
7272
<gitlab.port>8090</gitlab.port>
7373

74+
<maven-enforcer-plugin.maxJdkVersion>1.8</maven-enforcer-plugin.maxJdkVersion>
75+
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
76+
<maven-antrun-plugin.version>3.1.0</maven-antrun-plugin.version>
77+
7478
<sonar.projectKey>gitlab4j_gitlab4j-api</sonar.projectKey>
7579
<sonar.organization>gitlab4j</sonar.organization>
7680
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
@@ -106,7 +110,7 @@
106110
<plugin>
107111
<groupId>org.apache.maven.plugins</groupId>
108112
<artifactId>maven-compiler-plugin</artifactId>
109-
<version>3.7.0</version>
113+
<version>${maven-compiler-plugin.version}</version>
110114
<configuration>
111115
<source>${java.source.version}</source>
112116
<target>${java.target.version}</target>
@@ -126,6 +130,7 @@
126130
<plugin>
127131
<groupId>biz.aQute.bnd</groupId>
128132
<artifactId>bnd-maven-plugin</artifactId>
133+
<version>${bnd.version}</version>
129134
<executions>
130135
<execution>
131136
<goals>
@@ -260,7 +265,7 @@
260265
<configuration>
261266
<rules>
262267
<enforceBytecodeVersion>
263-
<maxJdkVersion>1.8</maxJdkVersion>
268+
<maxJdkVersion>${maven-enforcer-plugin.maxJdkVersion}</maxJdkVersion>
264269
<ignoreClasses>
265270
<ignoreClass>module-info</ignoreClass>
266271
</ignoreClasses>
@@ -348,6 +353,10 @@
348353
</execution>
349354
</executions>
350355
</plugin>
356+
<plugin>
357+
<groupId>org.apache.maven.plugins</groupId>
358+
<artifactId>maven-antrun-plugin</artifactId>
359+
</plugin>
351360
</plugins>
352361

353362
<pluginManagement>
@@ -422,6 +431,7 @@
422431
<groupId>jakarta.servlet</groupId>
423432
<artifactId>jakarta.servlet-api</artifactId>
424433
<version>${servlet.version}</version>
434+
<scope>provided</scope>
425435
</dependency>
426436

427437
<dependency>
@@ -490,7 +500,317 @@
490500
</plugins>
491501
</build>
492502
</profile>
493-
503+
<profile>
504+
<id>java8</id>
505+
<activation>
506+
<jdk>[,9)</jdk>
507+
</activation>
508+
<build>
509+
<pluginManagement>
510+
<plugins>
511+
<plugin>
512+
<groupId>org.apache.maven.plugins</groupId>
513+
<artifactId>maven-jar-plugin</artifactId>
514+
<version>3.2.0</version>
515+
<configuration>
516+
<archive>
517+
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
518+
</archive>
519+
</configuration>
520+
</plugin>
521+
<plugin>
522+
<groupId>org.apache.maven.plugins</groupId>
523+
<artifactId>maven-compiler-plugin</artifactId>
524+
<version>${maven-compiler-plugin.version}</version>
525+
<configuration>
526+
<source>${java.source.version}</source>
527+
<target>${java.target.version}</target>
528+
</configuration>
529+
</plugin>
530+
<plugin>
531+
<groupId>org.apache.maven.plugins</groupId>
532+
<artifactId>maven-failsafe-plugin</artifactId>
533+
<version>3.0.0-M5</version>
534+
<configuration>
535+
<groups>integration</groups>
536+
<includes>
537+
<include>**/*.java</include>
538+
</includes>
539+
</configuration>
540+
<executions>
541+
<execution>
542+
<phase>verify</phase>
543+
<goals>
544+
<goal>integration-test</goal>
545+
<goal>verify</goal>
546+
</goals>
547+
</execution>
548+
</executions>
549+
</plugin>
550+
</plugins>
551+
</pluginManagement>
552+
</build>
553+
</profile>
554+
<profile>
555+
<id>java9+</id>
556+
<activation>
557+
<jdk>[9,)</jdk>
558+
</activation>
559+
<properties>
560+
<jacoco.skip>true</jacoco.skip>
561+
<skipTests>true</skipTests>
562+
<animal.sniffer.skip>true</animal.sniffer.skip>
563+
<maven.test.skip>true</maven.test.skip>
564+
<maven.javadoc.skip>true</maven.javadoc.skip>
565+
</properties>
566+
<build>
567+
<pluginManagement>
568+
<plugins>
569+
<plugin>
570+
<groupId>biz.aQute.bnd</groupId>
571+
<artifactId>bnd-maven-plugin</artifactId>
572+
<version>${bnd.version}</version>
573+
<configuration>
574+
<bnd><![CDATA[
575+
Export-Package: org.gitlab4j.api.*
576+
-fixupmessages: "Classes found in the wrong directory";restrict:=error;is:=warning
577+
]]></bnd>
578+
</configuration>
579+
</plugin>
580+
</plugins>
581+
</pluginManagement>
582+
</build>
583+
</profile>
584+
<profile>
585+
<id>generate-jakarta-sources</id>
586+
<activation>
587+
<file>
588+
<missing>${basedir}/target/jakarta</missing>
589+
</file>
590+
<jdk>[9,)</jdk>
591+
</activation>
592+
<build>
593+
<pluginManagement>
594+
<plugins>
595+
<plugin>
596+
<groupId>org.apache.maven.plugins</groupId>
597+
<artifactId>maven-compiler-plugin</artifactId>
598+
<version>${maven-compiler-plugin.version}</version>
599+
<configuration>
600+
<release>8</release>
601+
<source>${java.source.version}</source>
602+
<target>${java.target.version}</target>
603+
<!-- recompile everything for target VM except the module-info.java -->
604+
<excludes>
605+
<exclude>module-info.java</exclude>
606+
</excludes>
607+
</configuration>
608+
<executions>
609+
<execution>
610+
<id>base-compile</id>
611+
<phase>compile</phase>
612+
<goals>
613+
<goal>compile</goal>
614+
</goals>
615+
<configuration>
616+
<release>8</release>
617+
<source>${java.source.version}</source>
618+
<target>${java.target.version}</target>
619+
<!-- recompile everything for target VM except the module-info.java -->
620+
<excludes>
621+
<exclude>module-info.java</exclude>
622+
</excludes>
623+
</configuration>
624+
</execution>
625+
</executions>
626+
</plugin>
627+
<plugin>
628+
<groupId>org.apache.maven.plugins</groupId>
629+
<artifactId>maven-antrun-plugin</artifactId>
630+
<version>${maven-antrun-plugin.version}</version>
631+
<executions>
632+
<execution>
633+
<id>generate-jakarta-sources</id>
634+
<phase>prepare-package</phase>
635+
<configuration>
636+
<target name="jakarta-compile">
637+
<property name="jakarta.src.dir" value="${basedir}/target/jakarta"/>
638+
<property name="jakarta.test.dir" value="${basedir}/target/jakarta-test"/>
639+
640+
<delete dir="${jakarta.src.dir}"/>
641+
<delete dir="${jakarta.test.dir}"/>
642+
<mkdir dir="${jakarta.src.dir}"/>
643+
<mkdir dir="${jakarta.test.dir}"/>
644+
645+
<echo message="project home: ${basedir}" />
646+
<echo message="java home: ${java.home}" />
647+
<echo message="JAVA_HOME: ${JAVA_HOME}"/>
648+
<echo message="java version: ${java.version}" />
649+
650+
<echo message="sources dir: ${basedir}/src/main/java"/>
651+
<echo message="jakarta dir: ${jakarta.src.dir}"/>
652+
653+
<copy todir="${jakarta.src.dir}">
654+
<fileset dir="${basedir}/src/main/java" includes="**/*.java">
655+
<contains text="javax."/>
656+
</fileset>
657+
</copy>
658+
659+
<copy todir="${jakarta.test.dir}">
660+
<fileset dir="${basedir}/src/test/java" includes="**/*.java">
661+
<contains text="javax."/>
662+
</fileset>
663+
</copy>
664+
665+
<exec dir="${basedir}" executable="/bin/bash">
666+
<arg value="-c"/>
667+
<arg value="JAVA_HOME=${java.home}; ./mvnw compile verify -P jakarta"/>
668+
</exec>
669+
</target>
670+
</configuration>
671+
<goals>
672+
<goal>run</goal>
673+
</goals>
674+
</execution>
675+
</executions>
676+
</plugin>
677+
</plugins>
678+
</pluginManagement>
679+
</build>
680+
</profile>
681+
<profile>
682+
<id>jakarta</id>
683+
<properties>
684+
<jakarta.source.version>9</jakarta.source.version>
685+
<jakarta.target.version>9</jakarta.target.version>
686+
<jersey.version>3.0.0</jersey.version>
687+
<servlet.version>6.0.0</servlet.version>
688+
<activation.version>2.1.1</activation.version>
689+
<maven.javadoc.skip>true</maven.javadoc.skip>
690+
<maven.jacoco.skip>true</maven.jacoco.skip>
691+
<maven-enforcer-plugin.maxJdkVersion>11</maven-enforcer-plugin.maxJdkVersion>
692+
</properties>
693+
<dependencies>
694+
<dependency>
695+
<groupId>jakarta.annotation</groupId>
696+
<artifactId>jakarta.annotation-api</artifactId>
697+
<version>2.0.0</version>
698+
</dependency>
699+
</dependencies>
700+
<build>
701+
<pluginManagement>
702+
<plugins>
703+
<plugin>
704+
<groupId>org.apache.maven.plugins</groupId>
705+
<artifactId>maven-jar-plugin</artifactId>
706+
<version>3.2.0</version>
707+
<configuration>
708+
<archive>
709+
<manifestEntries>
710+
<Multi-Release>true</Multi-Release>
711+
</manifestEntries>
712+
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
713+
</archive>
714+
</configuration>
715+
</plugin>
716+
<plugin>
717+
<groupId>org.apache.maven.plugins</groupId>
718+
<artifactId>maven-antrun-plugin</artifactId>
719+
<version>${maven-antrun-plugin.version}</version>
720+
<executions>
721+
<execution>
722+
<id>generate-jakarta-sources</id>
723+
<phase>generate-sources</phase>
724+
<configuration>
725+
<target>
726+
<property name="jakarta.src.dir" value="${basedir}/target/jakarta"/>
727+
<property name="jakarta.test.dir" value="${basedir}/target/jakarta-test"/>
728+
729+
<echo message="replace javax.servlet ====> jakarta.servlet"/>
730+
<echo message="replace javax.ws.rs ====> jakarta.ws.rs"/>
731+
<echo message="replace javax.annotation ====> jakarta.annotation"/>
732+
<replace dir="${jakarta.src.dir}" summary="true" includes="**/*.java">
733+
<replacefilter token="javax.servlet" value="jakarta.servlet"/>
734+
<replacefilter token="javax.ws.rs" value="jakarta.ws.rs"/>
735+
<replacefilter token="javax.annotation" value="jakarta.annotation"/>
736+
</replace>
737+
738+
<replace dir="${jakarta.test.dir}" summary="true" includes="**/*.java">
739+
<replacefilter token="javax.servlet" value="jakarta.servlet"/>
740+
<replacefilter token="javax.ws.rs" value="jakarta.ws.rs"/>
741+
<replacefilter token="javax.annotation" value="jakarta.annotation"/>
742+
</replace>
743+
</target>
744+
</configuration>
745+
<goals>
746+
<goal>run</goal>
747+
</goals>
748+
</execution>
749+
</executions>
750+
</plugin>
751+
<plugin>
752+
<groupId>org.apache.maven.plugins</groupId>
753+
<artifactId>maven-compiler-plugin</artifactId>
754+
<version>${maven-compiler-plugin.version}</version>
755+
<configuration>
756+
<release>9</release>
757+
<source>${jakarta.source.version}</source>
758+
<target>${jakarta.target.version}</target>
759+
<compileSourceRoots>
760+
<compileSourceRoot>${project.basedir}/target/jakarta</compileSourceRoot>
761+
</compileSourceRoots>
762+
<outputDirectory>${project.build.outputDirectory}/META-INF/versions/9</outputDirectory>
763+
</configuration>
764+
<executions>
765+
<execution>
766+
<id>java8-compile</id>
767+
<phase>compile</phase>
768+
<goals>
769+
<goal>compile</goal>
770+
</goals>
771+
<configuration>
772+
<release>8</release>
773+
<source>${java.source.version}</source>
774+
<target>${java.target.version}</target>
775+
</configuration>
776+
</execution>
777+
<execution>
778+
<id>jakarta-compile</id>
779+
<phase>compile</phase>
780+
<goals>
781+
<goal>compile</goal>
782+
</goals>
783+
<configuration>
784+
<release>9</release>
785+
<source>${jakarta.source.version}</source>
786+
<target>${jakarta.target.version}</target>
787+
<outputDirectory>${project.build.outputDirectory}/META-INF/versions/9
788+
</outputDirectory>
789+
</configuration>
790+
</execution>
791+
<execution>
792+
<id>jakarta-test-compile</id>
793+
<phase>test-compile</phase>
794+
<goals>
795+
<goal>testCompile</goal>
796+
</goals>
797+
<configuration>
798+
<release>9</release>
799+
<source>${jakarta.source.version}</source>
800+
<target>${jakarta.target.version}</target>
801+
<compileSourceRoots>
802+
<root>${project.basedir}/target/jakarta-test</root>
803+
</compileSourceRoots>
804+
<outputDirectory>${project.basedir}/target/test-classes
805+
</outputDirectory>
806+
</configuration>
807+
</execution>
808+
</executions>
809+
</plugin>
810+
</plugins>
811+
</pluginManagement>
812+
</build>
813+
</profile>
494814
</profiles>
495815

496816
</project>

0 commit comments

Comments
 (0)