英文:
Add Java CI with Maven workflow to Maven project with my own dependencies
问题
我有一个GitHub仓库,里面包含三个Maven项目:
- 客户端 (Client)
- 服务器 (Server)
- 引擎 (Engine)
我想要应用使用Maven的Java CI工作流程,配置如下:
# 该工作流将使用Maven构建Java项目,并缓存/还原依赖项以提高工作流执行时间
# 有关更多信息,请参见:https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
# 该工作流使用未经GitHub认证的操作。
# 这些操作由第三方提供,并受独立的服务条款、隐私政策和支持文档约束。
name: Java CI with Maven
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Build with Maven -> Client
run: mvn -B package --file client/pom.xml
- name: Build with Maven -> Engine
run: mvn -B package --file engine/pom.xml
- name: Build with Maven -> Server
run: mvn -B package --file server/pom.xml
# 可选:将完整的依赖关系图上传到GitHub,以改善Dependabot警报的质量,该存储库可以接收这些警报
- name: Update dependency graph
uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
问题出在Server的pom文件,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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.victorpiles.escacs</groupId>
<artifactId>server</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<!-- Engine -->
<dependency>
<groupId>org.victorpiles.escacs</groupId>
<artifactId>engine</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
因此,Server将Engine作为依赖项,而GitHub无法解析此依赖项。
Engine的pom如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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.victorpiles.escacs</groupId>
<artifactId>engine</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
运行工作流程时出现以下错误:
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< org.victorpiles.escacs:server >-------------------
[INFO] Building server 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
Warning: The POM for org.victorpiles.escacs:engine:jar:1.0-SNAPSHOT is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.282 s
[INFO] Finished at: 2023-03-20T15:12:47Z
[INFO] ------------------------------------------------------------------------
Error: Failed to execute goal on project server: Could not resolve dependencies for project org.victorpiles.escacs:server:jar:1.0-SNAPSHOT: Could not find artifact org.victorpiles.escacs:engine:jar:1.0-SNAPSHOT -> [Help 1]
Error:
Error: To see the full stack trace of the errors, re-run Maven with the -e switch.
Error: Re-run Maven using the -X switch to enable full debug logging.
Error:
Error: For more information about the errors and possible solutions, please read the following articles:
Error: [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
Error: Process completed with exit code 1.
英文:
I have a GitHub repo with this three Maven projects inside:
- Client
- Server
- Engine
I want to apply the Java CI with Maven workflow, the configuration is this one:
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: Java CI with Maven
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Build with Maven -> Client
run: mvn -B package --file client/pom.xml
- name: Build with Maven -> Engine
run: mvn -B package --file engine/pom.xml
- name: Build with Maven -> Server
run: mvn -B package --file server/pom.xml
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
- name: Update dependency graph
uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
The problem comes with the Server pom, looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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.victorpiles.escacs</groupId>
<artifactId>server</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<!-- Engine -->
<dependency>
<groupId>org.victorpiles.escacs</groupId>
<artifactId>engine</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
So the Server has the Engine as a dependency and GitHub can't resolve this dependency.
The pom of the Engine is the following:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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.victorpiles.escacs</groupId>
<artifactId>engine</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
The following error is thrown when running the Workflow:
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< org.victorpiles.escacs:server >--------------------
[INFO] Building server 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
Warning: The POM for org.victorpiles.escacs:engine:jar:1.0-SNAPSHOT is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.282 s
[INFO] Finished at: 2023-03-20T15:12:47Z
[INFO] ------------------------------------------------------------------------
Error: Failed to execute goal on project server: Could not resolve dependencies for project org.victorpiles.escacs:server:jar:1.0-SNAPSHOT: Could not find artifact org.victorpiles.escacs:engine:jar:1.0-SNAPSHOT -> [Help 1]
Error:
Error: To see the full stack trace of the errors, re-run Maven with the -e switch.
Error: Re-run Maven using the -X switch to enable full debug logging.
Error:
Error: For more information about the errors and possible solutions, please read the following articles:
Error: [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
Error: Process completed with exit code 1.
答案1
得分: 2
你的项目应该是一个多模块项目。
将一个 pom.xml
放入项目的根目录,列出其他目录作为 <modules>
。然后构建根 POM,一切都将自动构建,包括已解决的依赖项。
英文:
Your project should have been a multi-module project.
Put a pom.xml
into the root directory of the project which lists the other directories as <modules>
. Then you build the root POM and everything will be build automatically, with resolved dependencies.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论