Maven 和 Gradle 哪个更好?他们有什么区别?
有一个 README.md 文件,其中包含转换为 pom.xml 文件值的各种文本占位符。该文件位于路径上{project.basedir}/doc/README.md
,并且在构建项目时,它由maven-resources-plugin 插件处理,该插件将文本占位符转换并将其复制到项目根目录,并在下一步中复制到目标目录(所以它也在 JAR 根目录中):
README.md 文件的内容示例:
# ${project.name}
${project.description}
[[_TOC_]]
## Used Maven Dependencies
- [JUnit](https://junit.org/junit5/docs/${junit}/api/) v.${junit}
- [SELF4J](https://www.javadoc.io/static/org.slf4j/slf4j-api/${slf4j}/index.html) v.${slf4j}
- ...
## Build
Compiled and built at ${timestamp} with:
- Java: ${java.version}
- Maven: ${maven.version}
```xml
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
</dependency>
```
在 pom.xml 文件中,处理配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<project ...>
<!-- ... -->
<properties>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
<!-- ... -->
</properties>
<!-- ... -->
<build>
<!-- ... -->
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>replace-placeholders-in-readme</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/doc</directory>
<includes>
<include>README.md</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
<encoding>UTF-8</encoding>
</configuration>
</execution>
<execution>
<id>copy-readme-to-output</id>
<phase>compile</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}</directory>
<includes>
<include>README.md</include>
</includes>
</resource>
</resources>
<encoding>UTF-8</encoding>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
问题在于,为了执行所有这些转换,必须通过 maven(例如mvn verify
)在本地机器上构建,因为 否则,修改后的 README.md 文件将出现在程序集/JAR 文件中,但不在存储库中。例如,在 pom.xml 中某个依赖项的版本发生了变化,而在 README.md 文件中使用了旧版本/引用。
问题:是否有可能以任何方式配置 README.md 文件的自动生成,即使在本地机器上,甚至在 GitLab 端(在 gitlab-ci.yml 中注册)?理想情况下,我们希望在每次提交时生成一个文件并自动将其“推送”到存储库中。
相关链接
将项目推送到heroku时,我在maven中遇到错误:
$ git push heroku 枚举对象:718,完成。计数对象:100% (718/718),完成。使用多达 12 个线程的 Delta 压缩压缩对象:100% (439/439),完成。写入对象:100% (718/718),1.16 MiB | 1005.00 KiB/s,完成。总计 718(增量 309),重用 415(增量 165),打包重用 0 远程:压缩源文件...完成。远程:构建源:远程:远程:-----> 在 Heroku-20 堆栈上构建远程:-----> 确定要用于此应用程序远程的构建包:-----> Java 应用程序检测到远程: -----> 安装 OpenJDK 1.8... 远程完成: -----> 执行 Maven 远程: $ ./mvnw -DskipTests clean dependency:list install remote: [INFO] Scanning for projects... .. 。偏僻的:
[INFO] BUILD FAILURE 远程:[INFO] ---------------------------------------------------- -------------------------------- 远程:[INFO] 总时间:10.547 秒远程:[INFO] 完成时间: 2022-07-05T13:53:18Z 远程:[信息]------------------------------------ ------------------------------------远程:[错误]无法执行目标org.apache.maven .plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project springboot_touristsite: Fatal error compile: invalid target release: 11 -> [Help 1] remote:
[ERROR] remote: [ERROR] 查看错误的完整堆栈跟踪,使用 -e 开关重新运行 Maven。远程:[错误] 使用 -X 开关重新运行 Maven 以启用完整的调试日志记录。偏僻的:
[ERROR] remote: [ERROR] 有关错误和可能的解决方案的更多信息,请阅读以下文章:remote:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException 远程:远程:!错误:无法使用 Maven 远程构建应用程序:
很抱歉,此构建失败!如果您在应用程序代码中找不到问题,请远程:请提交工单以便我们提供帮助:https ://help.heroku.com/远程:远程:!推送被拒绝,无法编译 Java 应用程序。远程:远程:!推送失败的远程:验证部署...远程:远程:!推送到 springbootouristsite 被拒绝。远程:到 https://git.heroku.com/springboottouristsite.git ![远程拒绝] master -> master (pre-receive hook denied) 错误:未能将一些参考推送到“https://git.heroku.com/springboottouristsite.git”
我很尴尬的是正在下载jdk 1.8:
远程:-----> 安装 OpenJDK 1.8... 完成
所以我在application.properties中设置了java.runtime.version=11,我在项目结构中也设置了11,在rum文件中,但是还是下载了1.8
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.zaitsava</groupId>
<artifactId>springboot_touristsite</artifactId>
<version>1.0</version>
<name>springboot_touristsite</name>
<description>springboot_touristsite</description>
<properties>
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
<configuration>
<additionalProperties>
<encoding.source>${project.build.sourceEncoding}</encoding.source>
<encoding.reporting>${project.reporting.outputEncoding}</encoding.reporting>
<java.source>${maven.compiler.source}</java.source>
<java.target>${maven.compiler.target}</java.target>
</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
我知道 pom 文件中有一些不喜欢的地方,尤其是在 maven 插件中,但是究竟需要更改什么?
我为 1.18.2 版本创建了一个项目,尝试构建时有很多错误。
错误之一:
bad class file: /C:/Users/fokus/.m2/repository/io/papermc/paper/paper-api/1.18.2-R0.1-SNAPSHOT/paper-api-1.18.2-R0.1-20220614.230913-165.jar!/org/bukkit/entity/Player.class
class file has wrong version 61.0, should be 56.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
pom.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.spgerg.viskas.money</groupId>
<artifactId>Main</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>MoneyViskas</name>
<description>Plugin for money system.</description>
<properties>
<java.version>1.8</java.version>
<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.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>papermc-repo</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.18.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>