maven工程指定版本号并开启预览特性

pom.xml

    <properties>
        <java.version>23</java.version>
        <maven.compiler.source>23</maven.compiler.source>
        <maven.compiler.target>23</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
...
<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.13.0</version>
                <configuration>
                    <source>23</source>
                    <target>23</target>
                    <encoding>UTF-8</encoding>
                    <compilerArgs>
                        <arg>--enable-preview</arg>
                    </compilerArgs>
                    <release>23</release>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.5.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.mycompany.app.App</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

注:用maven-compiler-plugin来指定JDK版本和开启预览特性,用maven-shade-plugin打出带main主入口的可执行jar包。

posted @ 2024-08-15 19:01  漠孤烟  阅读(51)  评论(0)    收藏  举报