You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jenkins Docker环境下带重音目录名的Maven Assembly打包问题

解决Unix环境下Maven Assembly插件丢失带特殊字符文件夹的问题

看起来你遇到的核心问题是Unix环境下的文件编码与Maven/JVM的编码不匹配,导致带法语特殊字符è的règles文件夹在打包时被忽略。结合你的日志和尝试过的操作,我整理了几个关键的解决步骤:

1. 统一JVM和Maven的编码为UTF-8

从你的Jenkins日志可以看到,初始环境的platform encoding: ANSI_X3.4-1968(ASCII编码),这会导致Maven无法正确识别带非ASCII字符的文件名。即使你在插件里设置了encoding=UTF-8,还需要确保整个JVM和Maven进程都使用UTF-8:

在你的Pipeline脚本中添加环境变量配置:

withMaven(globalMavenSettingsConfig: 'empty-global-settings', mavenSettingsConfig: Constants.CONFIG_SETTINGS_ID) {
    // 强制JVM和Maven使用UTF-8编码
    env.JAVA_TOOL_OPTIONS = "-Dfile.encoding=UTF-8"
    env.MAVEN_OPTS = "-Dfile.encoding=UTF-8"
    
    sh "pwd"
    sh "ls -lrt"
    sh "ls -lrt /home/jenkins/workspace/xxx_Common_xxxGenerate/xxx-xxx-commonutility/xxx-xxx-CommonUtility-rules"
    sh "ls -lrt /home/jenkins/workspace/xxx_Common_xxxGenerate/xxx-xxx-commonutility/xxx-xxx-CommonUtility-rules/règles"
    sh "$MVN_CMD deploy -X"
}

2. 确保maven-assembly-plugin版本正确生效

你的POM里配置的是3.3.0版本,但调试日志显示实际使用的是2.6版本:

[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-assembly-plugin:2.6:single'

这说明插件版本可能被父POM覆盖,或者Maven缓存了旧版本。解决方法:

  • 在插件配置中添加<inherited>false</inherited>,强制使用你指定的版本:
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.3.0</version>
        <inherited>false</inherited> <!-- 新增 -->
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>single</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <encoding>UTF-8</encoding> <!-- 明确指定编码 -->
            <descriptors>
                <descriptor>assembly.xml</descriptor>
            </descriptors>
        </configuration>
    </plugin>
    
  • 清理Maven插件缓存:在Jenkins容器中执行rm -rf ~/.m2/repository/org/apache/maven/plugins/maven-assembly-plugin,然后重新构建。

3. 在Assembly配置中明确文件集编码

在assembly.xml的<fileSet>节点中添加编码配置,确保插件遍历目录时用UTF-8解析文件名:

<fileSet>
    <outputDirectory></outputDirectory>
    <directory>${basedir}</directory>
    <excludes>
        <exclude>target</exclude>
    </excludes>
    <encoding>UTF-8</encoding> <!-- 新增 -->
</fileSet>

4. 确保Git克隆代码时使用UTF-8编码

如果你的代码是通过Git拉取到Jenkins的,需要确保Git使用UTF-8处理文件名:

  • 在Jenkins的全局Git配置中设置core.encoding=UTF-8
  • 或者在Pipeline脚本拉取代码前执行:
    git config --global core.encoding UTF-8
    

5. 考虑升级Maven版本

你当前使用的Maven 3.2.5是2014年的老版本,对非ASCII文件名的支持存在已知问题。升级到Maven 3.6.x或更高版本(比如3.8.6),能更好地处理UTF-8编码的文件和目录。

验证方法

修改后重新构建,查看调试日志中是否出现adding directory xxx-xxx-xxxFramework-rules/règles/的记录,如果有,说明文件夹已被正确识别并打包。

内容的提问来源于stack exchange,提问作者Stéphane GRILLON

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 12:47:46