【问题标题】:maven-assembly-plugin generates tar incompatible with python's tarfile (works with bsdtar)maven-assembly-plugin 生成与 python 的 tarfile 不兼容的 tar(与 bsdtar 一起使用)
【发布时间】:2014-04-15 12:12:27
【问题描述】:

作为自动化部署管道的一部分,我正在使用maven-assembly-plugin 创建一个tar.gz 文件,然后使用python 的tarfile 模块解压它。

提取失败并出现异常:

Traceback (most recent call last): File "tarfile-assembly-testcase/extract_tar.py", line 20, in <module> tarfile.open(fileobj=f, mode='r:gz') File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tarfile.py", line 1676, in open return func(name, filemode, fileobj, **kwargs) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tarfile.py", line 1725, in gzopen **kwargs) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tarfile.py", line 1703, in taropen return cls(name, mode, fileobj, **kwargs) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tarfile.py", line 1572, in __init__ self.firstmember = self.next() File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tarfile.py", line 2335, in next raise ReadError(str(e)) ReadError: invalid header

压缩和未压缩的 tar 文件都会发生这种情况。可以从命令行解压缩相同的文件。我已经用bsdtar 2.8.3tar (GNU tar) 1.26 对其进行了测试。我正在使用python 2.7

请尝试我在github上发布的demo。这是一个 maven 项目,运行 mvn package 它将创建一个包含项目源的 tar.gz(仅 pom.xml)。包含的python脚本尝试使用tarfile提取它。

有什么想法可以让maven-assembly-plugin 和python 的tarfile 配合得很好吗?

【问题讨论】:

标签: python maven tar maven-assembly-plugin tarfile


【解决方案1】:

我发现了问题。复制我在 Stackoverflow 中找到的 here (see "Version pinning" paragraph) 的解决方案以供后代使用。

maven-assembly-plugin 从 2.4 版开始导入有缺陷的 plexus-archiver 版本。强制maven-assembly-plugin 使用最新的plexus-archiver 就可以了。正如链接帖子中所建议的,我还升级了plexus-io

这里是代码

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.4</version>
    <dependencies>
        <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-archiver</artifactId>
            <version>2.4.4</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-io</artifactId>
            <version>2.0.10</version>
        </dependency>
    </dependencies>
</plugin>

【讨论】:

  • 您需要两者还是只需要其中之一?对于 2.5 的 maven-assembly-plugin,plexus-archiver 会更新。
猜你喜欢
  • 2013-02-19
  • 1970-01-01
  • 2014-12-16
  • 2012-06-09
  • 2016-01-28
  • 2013-08-19
  • 2012-10-23
  • 2021-11-09
  • 1970-01-01
相关资源
最近更新 更多