来自 itext 的 jasper 报告中的依赖性错误

Dependency error in jasper-reports from itext

从昨天开始,由于 iText jar,我在使用 maven 进行编译时遇到了问题。 我的项目依赖于 jasperreports-2.0.1,它依赖于 itext-1.02b 或更高版本。

<dependency>
    <groupId>com.lowagie</groupId>
    <artifactId>itext</artifactId>
    <version>[1.02b,)</version>
    <scope>compile</scope>
</dependency>

也就是maven中的日志报错:

Failed to collect dependencies for [jasperreports:jasperreports:jar:2.0.1 (compile)]: Failed to read artifact descriptor for com.lowagie:itext:jar:4.2.2: Could not transfer artifact com.itextpdf:itextpdf:pom:4.2.2 from/to jaspersoft (http://www.jasperforge.org/maven2): Access denied to http://www.jasperforge.org/maven2/com/itextpdf/itextpdf/4.2.2/itextpdf-4.2.2.pom. Error code 403, Forbidden -> [Help 1] 

我看到 here 来自 Amedee Van Gasse 的评论,其中提到了没有 jar 的 4.2.2 版本。

为什么1.02b版本附加到4.2.2?

编辑: Jasper-reports 使用开放版本范围:

[1.02b,)

这个范围告诉 maven 获取库的最新版本。

随着 iText 的 update 添加没有 jar 的新版本 Pom 并将 maven-central 的 maven-metadata 编辑为该无 jar 版本会使编译崩溃到所有 jar,具体取决于最新的形式 com.lowagie图书馆。

在本地更新您的 maven-metadata-central.xml(以及其他元数据,如果您的公司有自己的 nexus.public)来自...m2\repository\com\lowagie\itext 那个作品。临时解决方案,直到 iText 更新元数据或所有对其最新版本有依赖关系的公司更新它的 pom

<metadata modelVersion="1.1.0">
  <groupId>com.lowagie</groupId>
  <artifactId>itext</artifactId>
  <versioning>
    <latest>4.2.1</latest>
    <release>4.2.1</release>
    <versions>
      <version>0.99</version>
      <version>1.1.4</version>
      <version>1.02b</version>
      <version>1.2.3</version>
      <version>1.3</version>
      <version>1.3.1</version>
      <version>1.4</version>
      <version>1.4.8</version>
      <version>2.0.1</version>
      <version>2.0.6</version>
      <version>2.0.7</version>
      <version>2.0.8</version>
      <version>2.1.0</version>
      <version>2.1.2</version>
      <version>2.1.3</version>
      <version>2.1.4</version>
      <version>2.1.5</version>
      <version>2.1.7</version>
      <version>4.2.0</version>
      <version>4.2.1</version>
    </versions>
    <lastUpdated>20150709153501</lastUpdated>
  </versioning>
</metadata>

我们有同样的问题。为了解决这个问题,我们删除了 Maven 配置的代理参数,并更改了最新版本的 maven-metadata-central(在您的存储库的文件夹 com\lowagie\itext 中)。

一个糟糕的解决方案,但暂时有效:/

问题确实出在jasper-reports的POM中:

<dependency>
  <groupId>com.lowagie</groupId>
  <artifactId>itext</artifactId>
  <version>[1.02b,)</version>
  <scope>compile</scope>
</dependency>

Jasper-reports 至少从 2012 年 11 月开始分发(修改过的)iText 2.1.7(如果没记错的话),所以如果你的 jasper-reports 版本仍然依赖于 1.02b 以上,一定是很老的版本了。

iText 上的 jasper-reports 依赖应更改为:

<dependency>
  <groupId>com.lowagie</groupId>
  <artifactId>itext</artifactId>
  <version>[1.02b,2.1.7]</version>
  <scope>compile</scope>
</dependency>

或者只是:

<dependency>
  <groupId>com.lowagie</groupId>
  <artifactId>itext</artifactId>
  <version>2.1.7</version>
  <scope>compile</scope>
</dependency>

这与这个问题有关:How do I tell Maven to use the latest version of a dependency? 该页面充满了关于始终为您的依赖项使用最新版本的警告。它会降低构建的可重复性。

2.1.7 是 iText Group NV 公司(或其法定前身)发布的最后一个 iText 版本,组 ID 为 com.lowagie。 iText Group NV 公司发布的下一个 iText 版本是 5.0.0,带有 com.itextpdf groupId,这意味着它与您当前的代码二进制不兼容。还有 AGPL 许可证更改的问题,但这超出了 Whosebug 的范围,我想将我的回答限制在技术问题上。

2.1.75.0.0 之间的任何其他 iText 版本,如 4.2.04.2.1,都是其他公司的分支。根据 Apache 的 Guide to uploading artifacts to the Central Repository (https://maven.apache.org/guides/mini/guide-central-repository-upload.html),这些公司应该使用不同的 groupId,因为页面在他们的常见问题解答中明确指出:

I have a patched version of the foo project developed at foo.com, what groupId should I use? When you patch / modify a third party project, that patched version becomes your project and therefore should be distributed under a groupId you control as any project you would have developed, never under com.foo. See above considerations about groupId.

长话短说;博士 如果您不想更改代码,请告诉您的 Maven 仅获取 iText 2.1.7。

我在使用 Maven 2.2.1 时遇到了同样的问题,我使用 Maven 3.2.3 及其作品重新构建了我的项目!

您必须使用Maven 3 来解决您的问题,该错误似乎在此版本中得到解决。

一个更简单的解决方案可能是升级到更新版本的 jasperreports。版本 6.1.0 对 iText 具有此依赖性:

<dependency>
    <groupId>com.lowagie</groupId>
    <artifactId>itext</artifactId>
    <version>2.1.7.js2</version>
    <scope>compile</scope>
</dependency>

不再 "floating" 依赖 iText,它是为 jasperreports 定制的版本!

请参阅 http://mvnrepository.com/artifact/net.sf.jasperreports/jasperreports/6.1.0 了解完整的 pom.xml

我们决定保持相同的 jasperreport 版本并在冲突的 pom 中进行此更改:

<dependencies>
    <dependency>
            <groupId>jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
            <version>2.0.1</version>
            <exclusions>
                <exclusion>
                    <groupId>com.lowagie</groupId>
                    <artifactId>itext</artifactId>
                </exclusion>
            </exclusions>           
    </dependency>
    <dependency>
        <groupId>com.lowagie</groupId>
        <artifactId>itext</artifactId>
        <version>2.1.7</version>
    </dependency>
...
</dependencies>

编辑:将依赖项更改为 2.1.7 以确保将来可以编译

JasperReports 修复了 iText,修复了一些错误。因此,您必须在 pom/gradle 文件中添加修补后的 iText 存储库 [1]。

[1] http://jasperreports.sourceforge.net/maven2/

下面是 gradle 片段,供您在使用 jasper 报告 6.1.1 时参考。

repositories {
 mavenLocal()
    mavenCentral()
    maven { url "http://repo.spring.io/release" }
    maven { url "https://jaspersoft.jfrog.io/artifactory/third-party-ce-artifacts/" }
    maven { url "http://jasperreports.sourceforge.net/maven2/" }
}

我正在使用 gradle,对于当前版本 6.8.2,我遇到了以下构建错误:
> Could not find com.lowagie:itext:2.1.7.js6

所以我将 http://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts/ 添加为存储库,现在可以使用了。

repositories {
    mavenCentral()
    maven { url "https://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts/" }
}

dependencies {
    compile 'net.sf.jasperreports:jasperreports:6.8.0'
}

编辑: 如果您使用此解决方案并突然收到类似

的错误
> Could not resolve com.lowagie:itext:2.1.7.js6.
    > Could not parse POM http://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts/com/lowagie/itext/2.1.7.js6/itext-2.1.7.js6.pom
       > The element type "hr" must be terminated by the matching end-tag "</hr>".

这是因为 jfrog 存储库禁用了 http,现在只允许使用 https。出于某种原因,这会创建一个包含以下内容的损坏的 pom

<html>
<head><title>308 Permanent Redirect</title></head>
<body>
<center><h1>308 Permanent Redirect</h1></center>
<hr><center>nginx</center>
</body>
</html>

解决方案:将存储库 url 中的 http 替换为 https

2k19 搜索者的答案

工件:

<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>

现在已弃用

最好将其从 jasperreports 中排除并手动添加新的 itext 依赖项

<dependency>
    <groupId>jasperreports</groupId>
    <artifactId>jasperreports</artifactId>
    <version>6.10.0</version> <!--(or higher)-->
    <exclusions>
        <exclusion>
            <groupId>com.lowagie</groupId>
            <artifactId>itext</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>com.itextpdf</groupId>
    <artifactId>itextpdf</artifactId>
    <version>5.5.13</version> <!--(or higher)-->
</dependency>

我正在维护一些遗留代码,我遇到了同样的问题。我找到的解决方案是将以下内容添加到 pom.xml:

<repositories>
  <repository>
    <id>jasper-3rd-party</id>
    <name>Jasper3rdParty</name>
    <url>http://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts/</url>
  </repository>
</repositories>

<dependencies>

  <dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports</artifactId>
    <version>6.12.2</version>
  </dependency>

  <!-- More dependencies like: commons-collections4, org.apache.xmlgraphics, etc -->

  <dependency>
    <groupId>com.lowagie</groupId>
    <artifactId>itext</artifactId>
    <version>2.1.7.js4</version>
  </dependency>

</dependencies>

用于测试此代码的 JasperReports 版本已于 Mar/2020 发布。希望这对您有所帮助!

对我来说“修复”是从 jasperreports 版本 5.5.0 切换到 4.5.1 LOL。 (不依赖于 itext)

然后它不依赖于自定义的、看似未发布的依赖版本的 itext(在我的例子中是 2.1.7.js2)。

您可以从 jasper 人员那里下载 2.1.7.js2.jar 并在本地将其发布到您“自己的”自定义 maven 存储库,甚至是您本地的 ~/.m2/repository(呃)。我什至看到人们使用自定义 ivy 命令将其本地副本“发布”到本地服务器(ivy 或 maven)。

或在其他答案中添加回购协议。或者只是手动将其指定为 2.1.7,它在主回购等中(但是你会错过一些错误修复)。

如果您正在使用 gradle 请注意 下面 jaspersoft 软件包的 url 已从这个更改:

maven{ url "http://jaspersoft.artifactoryonline.com/jaspersoft/third-party-ce-artifacts" }

这里是这个:

maven { url "https://jaspersoft.jfrog.io/artifactory/third-party-ce-artifacts" }

这适用于最新的 jasper-reports 版本 6.17.0maven 3.8.1,尤其是 com.alexnederlof 版本 [=16] 中的 jasperreports-plugin =]:

<project>
    ...
    <repositories>
        <!-- JasperSoft, they modified a standard library for their own special needs -->
        <repository>
            <id>jaspersoft-third-party</id>
            <url>https://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts/</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <!-- JasperSoft, they modified a standard library for their own special needs -->
        <pluginRepository>
            <id>jaspersoft-third-party</id>
            <url>https://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts/</url>
        </pluginRepository>
    </pluginRepositories>
    ...

重要的是要知道,您可能必须提供 <repositories> 还有 <pluginRepositories>(取决于您的设置和传递依赖项)。

我遇到了同样的问题,

刚刚发现 https://jaspersoft.jfrog.io/artifactory/third-party-ce-artifacts 无法被 public 访问,您需要将 artifactory 目录更改为 jaspersoft 目录。

对于 Maven,您可以使用 pom.xml

中的以下存储库
<repositories>
  <repository>
    <id>jaspersoft-third-party</id>
    <url>https://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts/</url>
  </repository>
</repositories>