iText 版本 4.2.1 在 Maven 中央存储库中重定向

iText version 4.2.1 redirected in maven central repository

我们在我们的一个项目中使用 iText 来生成 PDF 报告,正是 4.2.1 版本,因为它是最后一个免费版本。

<dependency>
   <groupId>com.lowagie</groupId>
   <artifactId>itext</artifactId>
   <version>4.2.1</version>
</dependency>

今天早上当我在一台新机器上克隆存储库时,我遇到了很多编译器错误,因为 maven 重定向到版本 5.5.6 并且导入失败。在我们的研究中,我们发现 maven central 中的 pom 文件上周发生了变化。以后好像不能再像之前那样添加jar依赖了

谁能告诉我,是否还有办法通过 maven 将 iText 集成到 4.2.1 版本中?

第一个解决方案

您可以在本地下载jar,然后使用以下命令在本地安装。

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> 
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>

使用您喜欢的groupId、artifactId、版本和包装。

在这种情况下:

mvn install:install-file -Dfile=itext.jar -DgroupId=com.lowagie
-DartifactId=itext -Dversion=4.2.1 -Dpackaging=jar

第二种方案:

你也可以下载jar到本地,用下面的依赖组引用

<dependency>
    <groupId>com.lowagie</groupId>
    <artifactId>itext</artifactId>
    <version>4.2.1</version>
    <scope>system</scope>
    <systemPath>/PATHTOJAR/itext.jar</systemPath>
</dependency>

如文档所述here, the people who published the iText forks versions 4.x.y didn't follow the rules as explained by Apache

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.

他们使用 groupId 发布了 iText 的非官方版本,这让人们相信他们使用的是 iText 的原始版本,但事实并非如此。这个错误引起了很多混乱和沮丧。

为避免混淆,iText Group 收回了 groupId,这样任何第三方都无法将侵犯第三方权利的软件甚至恶意软件引入您的代码库(这是一个当您允许 Maven 自动升级时您承担的风险)。

您关于 iText 4.2.1 是最后一个免费版本的说法是不正确的。 iText 5 之前的 iText 版本存在一些严重的问题,但这是另一个讨论,也是 JavaOne 2015 会议演讲的主题 IANAL: What Developers Should Know About IP and Legal.

无论如何,最简单的解决方案是将依赖项更改为:

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

有关更多背景信息,请参阅 this answer in answer to Dependency error in jasper-reports from itext

我在使用 Gradle 时遇到了同样的问题。

在我的 build.gradle 文件中,在依赖项下,

compile 'com.lowagie:itext:4.2.1'

会获取 itextpdf-5.5.6.jar

运行命令

gradle myapp:dependencies

会显示这样的传递依赖:

\--- com.lowagie:itext:4.2.1
     \--- com.itextpdf:itextpdf:5.5.6

我的解决方案是将我拥有的原始 itext-4.2.1.jar 的副本上传到我们的 Nexus 存储库,并给它一个不同的版本号。

我知道这是一个旧线程,但由于一些随机问题我刚刚清除了我的 .m2 文件夹,不幸的是然后得到了“工件 com.lowagie:itext:jar:4.2.1已移至 com.itextpdf:itextpdf:jar:5.5.6".

刚刚在试图记住我们是如何修复的时候遇到这个问题,所以认为我是 post 解决方案,但我们不得不停止它尝试升级。

转到 %UserProfiles%\.m2\repository\com\lowagie\itext.2.1\

编辑 itext-4.2.1.pom 并从底部删除以下部分,它不会再打扰您,您可以愉快地使用 4.2.1 :-

  <distributionManagement>
      <relocation>
          <groupId>com.itextpdf</groupId>
          <artifactId>itextpdf</artifactId>
          <version>5.5.6</version>
          <message>After release 2.1.7, iText moved from the MPLicense to the AGPLicense.
          The groupId changed from com.lowagie to com.itextpdf and the artifactId from itext to itextpdf.
          See http://itextpdf.com/functionalitycomparison for more information.</message>
      </relocation>
  </distributionManagement>