Can I hold iText5 and iText7 in the same maven project? - java

We have a maven project that uses iText5. We would like to migrate to iText7. There are many parts that use the old library. Are there any contraindications in temporarily keeping both libraries as a reference in the pom and using the old version in some parts and the new in others? We will gradually replace the old one. We will permanently delete the old one after a long process of refactoring and testing.

when using itext5 and itext7 gives the same file errors.
need to exclude that file using the packaging option.
The below code will fix the compile-time build failed
android {
packagingOptions {
exclude 'com/itextpdf/io/font/cmap/HYGoThic-Medium.properties'
}
}
The below code will fix the Run-time build and make the application install
android {
packagingOptions {
exclude 'com/itextpdf/io/font/cmap/cjk_registry.properties'
exclude 'com/itextpdf/io/font/cmap/HeiseiKakuGo-W5.properties'
exclude 'com/itextpdf/io/font/cmap/HeiseiMin-W3.properties'
exclude 'com/itextpdf/io/font/cmap/HYGoThic-Medium.properties'
exclude 'com/itextpdf/io/font/cmap/HYSMyeongJo-Medium.properties'
exclude 'com/itextpdf/io/font/cmap/HYSMyeongJoStd-Medium.properties'
exclude 'com/itextpdf/io/font/cmap/KozMinPro-Regular.properties'
exclude 'com/itextpdf/io/font/cmap/MHei-Medium.properties'
exclude 'com/itextpdf/io/font/cmap/MSung-Light.properties'
exclude 'com/itextpdf/io/font/cmap/MSungStd-Light.properties'
exclude 'com/itextpdf/io/font/cmap/STSong-Light.properties'
exclude 'com/itextpdf/io/font/cmap/STSongStd-Light.properties'
exclude 'com/itextpdf/io/font/cmap_info.txt'
}
}

Related

Replace android.support.v4.util.ArraySet with androidx.collection.ArraySet in Maven library

I have a 3rd party library that depends on:
import android.support.v4.util.ArraySet;
And I want to use the latest Android libraries in the rest of my project:
import androidx.collection.ArraySet;
However, since I'm getting the library via Maven, I can't seem to force it to replace the v4 dependency for the androidx one and have it refer to the right class.
I've already tried:
implementation 'androidx.collection:collection:1.1.0'
implementation('some-library:v1') {
exclude group: 'com.android.support', module: 'support-v4'
}
And:
configurations.all {
resolutionStrategy.dependencySubstitution {
substitute module('com.android.support:support-v4') with module('androidx.collection:collection:1.1.0')
}
}
I've even tried a few more things including the force=true for the dependencies I want.
However I'm still getting:
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/util/ArraySet;
How can I tell Gradle to resolve the imports for android.support.v4.util.ArraySet to androidx.collection.ArraySet when I don't have access to the source code?
As per the Migrate to AndroidX guide:
android.enableJetifier=true
The Android plugin automatically migrates existing third-party libraries to use AndroidX by rewriting their binaries.
So this rewriting of Maven dependencies is exactly what Jetifier does for you. Make sure you've added the android.enableJetifier=true to your gradle.properties file to enable Jetifier.

How can I exclude directory while using gradle's "compile project"?

There are two modules in my project and module A depends on module B.
For building this with Gradle I've used a simple code in the A's build.gradle file:
compile project(":B")
My issue is a collision of resources directories.
What I want to do is to exclude certain B's module "resource" directory.
What I've tried:
compile (project(":B")) {
exclude group : 'src.main', module : 'resources'
}
What I've tried as well:
compile(project(":B")) {
exclude module: 'src'
exclude module: 'main'
exclude module: 'src/main'
exclude module: 'src.main'
}
By excluding the root of module B, I'm expecting to get failed build of whole project, but nothing happens.
P.S. Every time I'm running build, I'm cleaning compiled jars, so they are not cached.
Gradle modules don't work like this. A java module is the compiled classes plus the resources. You can only exclude dependencies (ie whole modules or jars) using your attempted exclude method. You can't exclude a specific part (eg a directory) of a dependency
In my opinion excluding things is an anti-pattern. I suggest breaking things onto smaller pieces and joining them together (ie "include" instead of "exclude")
So I suggest you create a ":common" project which both "A" and "B" have as a dependency. All common stuff goes in common and any specific stuff goes in A or B

Gradle - Exclude spring.xml from a dependency

Is there a way to exclude spring.xml from a gradle dependency? I have enabled autoscanning for all spring.xmls but do not want spring.xml from a specific jar to considered.
compile('com.savnet.ofm:ofm-client:16.08') {
exclude group: "net.sf.saxon", module: "saxon-xpath"
exclude group: 'hibernate'
}
You mean excluding a file from a JAR you depend on?
If so, then as far as I know there is no per-se supported way.
But you can make it manually.
Something like the following which is totally made up right now and not tested, so take this as a starting point that might work or might need some polishing to work.
configurations { foo }
dependencies { foo 'com.savnet.ofm:ofm-client:16.08'}
sourceSets { main.compileClasspath += configurations.foo }
task fooJar(type: Jar) {
archiveName = 'foo.jar'
from zipTree(configurations.foo.singleFile)
exclude 'spring.xml'
}
And then use fooJar output as runtime library.

Remove dependency in Gradle

In my project I have to libraries that uses com.google.javascript:closure-compiler. Due to some jars problem I want to exclude one. To do this I wrote this code:
compile('com.bertramlabs.plugins:asset-pipeline-core:2.8.1') {
exclude group: 'com.google.javascript', module: 'closure-compiler'
}
When I run ./gradlew dependecies old jar seems to be removed.
My problem occurs when I run ./gradlew install and import my lib in another project, because in another project I have both jars. How can I remove it?
You could try adding a provided configuration as described here.
Once that is in place, try changing your code to something like:
provided('com.bertramlabs.plugins:asset-pipeline-core:2.8.1') {
exclude group: 'com.google.javascript', module: 'closure-compiler'
}

Gradle exclude group from dependant subproject

Given a gradle project A having a dependency on project B (no common parent)
compile project('B'){
exclude group: 'org.slf4j'
}
how do we exclude transitive dependency group from a project we depend upon? (this piece of script will fail as there is no exclude for compile projet(..))
and more general question : is there an elegant way to exclude a particular group from all dependancies except if its a first level dependency?
for example we may have a bunch of libraries, and each may declare its logging environment, but by excluding all known groups of slf4j, its implementations and declaring specific version, we would ensure we don't have any version conflicts and would control version on module level.
Here is an example from the Gradle documentation of how to exclude a transitive dependency (I guess that is what you meant by "except if its a first level dependency") on project level:
configurations {
compile.exclude module: 'commons'
all*.exclude group: 'org.gradle.test.excludes', module: 'reports'
}
See 52.4.7. Excluding transitive dependencies here
You can either specify the dependency directly with the desired version or use a forced version resolution strategy

Categories