简体   繁体   English

gradle和外部jar的问题 - 找不到jar

[英]Problem with gradle and external jar - jar not found

I have a problem with Gradle. 我有Gradle的问题。 I want to use an externally provided Jar: itext-2.1.7.js6.jar , it is a patched version used by JasperReports. 我想使用外部提供的Jar: itext-2.1.7.js6.jar ,它是JasperReports使用的修补版本。

In the project structure, I have a /libs directory, containing 2 files: fonts.jar and itext-2.1.7.js6.jar 在项目结构中,我有一个/libs目录,包含2个文件: fonts.jaritext-2.1.7.js6.jar

Part of my gradle.build file looks like this: 我的gradle.build文件的一部分如下所示:

compile fileTree(dir: 'libs', include: ['*.jar'])
implementation group: 'net.sf.jasperreports', name: 'jasperreports', version: '6.7.1'
implementation group: 'net.sf.jasperreports', name: 'jasperreports-functions', version: '6.8.0'
implementation group: 'joda-time', name: 'joda-time', version: '2.9.9'
//implementation group: 'hu.blackbelt.bundles.itext', name: 'com.lowagie.itext', version: '2.1.7-1'

The last dependency is commented out cause I want to use the external JAR instead of the original iText. 最后一个依赖项被注释掉,因为我想使用外部JAR而不是原始的iText。

When I am trying to run my app I get: 当我试图运行我的应用程序时,我得到:

BUILD FAILED in 0s
1 actionable task: 1 executed
Could not find com.lowagie:itext:2.1.7.js6.
Required by:
    project : > net.sf.jasperreports:jasperreports:6.7.1

What am I doing wrong? 我究竟做错了什么? Everything is fine with my fonts.jar , so I think that it should be the same with iText, but it isn't... 我的fonts.jar一切都很好,所以我认为iText应该是一样的,但它不是......

As can be seen in the pom file of jasperreports , there is an explicit dependency on com.lowagie:itext:2.1.7.js6 which can also be found in a specific Jasper Reports repository 由于可以在可见pom文件jasperreports ,对的显式依赖com.lowagie:itext:2.1.7.js6这也可以在发现特定的Jasper报表库

The reason this works transparently in Maven is that Maven will use the repositories defined in a pom file, while Gradle will not use them, as they could be a source of insecurity. 这在Maven中透明地工作的原因是Maven将使用pom文件中定义的存储库,而Gradle将不使用它们,因为它们可能是不安全的来源。

You have two options: 您有两种选择:

  1. Add that repository, potentially using repository filtering to only serve these artifacts from there and then remove the file from libs 添加该存储库,可能使用存储库过滤仅从那里提供这些工件,然后从libs删除该文件
  2. Add an exclude to jasperreports so that it no longer tries to fetch that dependency. 将排除添加到jasperreports以便它不再尝试获取该依赖项。 And instead the runtime code will use the version found in libs . 而运行时代码将使用libs的版本。 You just forget about transitive dependency management in this case, for example when upgrading jasperreports and getting (or not) an updated version from their dependency declaration. 在这种情况下,您只是忘记了传递依赖关系管理,例如,在升级jasperreports并从其依赖关系声明中获取(或不获取)更新版本时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM