Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid Gradle Module Metadata - optional dependencies not optional #99

Open
fransflippo opened this issue Jul 29, 2020 · 5 comments · May be fixed by #116
Open

Invalid Gradle Module Metadata - optional dependencies not optional #99

fransflippo opened this issue Jul 29, 2020 · 5 comments · May be fixed by #116

Comments

@fransflippo
Copy link

According to gradle/gradle#13656 (comment) , dom4j has invalid Gradle Module Metadata which can cause projects with a dependency on dom4j to pull in the optional pull-parser:pull-parser:2 dependency as well. This parser seems to have some issues which can result in an error org.xml.sax.XMLReader.setProperty("http://xml.org/sax/properties/lexical-handler", this) that the default XML parser on the JVM doesn't throw.

Can you look at fixing the Gradle Module Metadata?

Thanks!

halfninja added a commit to halfninja/dom4j that referenced this issue Jan 15, 2021
dom4j#99)

The result is the same in the POM - they get marked as optional - but for Gradle Module Metadata they become individual features which users can request.
@robert-gurol-signavio
Copy link

Workarounds

  • It's not a problem using Gradle 5, it seems
  • You can add a hard exclude of this optional dependency like so (if that's an option for you):
    implementation(group: 'org.dom4j', name: 'dom4j', version: "2.1.3") {
        exclude group: "pull-parser", module: "pull-parser"
    }

(Gradle, Groovy DSL)

@symaxian
Copy link

Confirming that this issue first appeared in Gradle 6.0.

To exclude all optional dependencies of dom4j:

compile(group: 'org.dom4j', name: 'dom4j', version: '2.1.3') {
	exclude module: 'pull-parser'
	exclude module: 'jaxen'
	exclude module: 'xpp3'
	exclude module: 'xsdlib'
	exclude module: 'stax-api'
	exclude module: 'jaxb-api'
}

@Vampire
Copy link

Vampire commented Apr 30, 2021

excludes are actually not the semantically correct way to fix invalid metadata.
That's more symptom treatment, like calling Thread.sleep to "fix" multi-threading issues or SwingUtilities.invokeLater to "fix" GUI issues.
Instead component metadata rules should be the tool of choice.
As all dependencies are optional, a simple one would be:

dependencies {
   components {
       withModule('org.dom4j:dom4j', ClearDependencies)
   }
}

class ClearDependencies implements ComponentMetadataRule {
   void execute(ComponentMetadataContext context) {
       context.details.allVariants { withDependencies { clear() } }
   }
}

(c) melix from gradle/gradle#13656 (comment)

twincitiesguy added a commit to EMCECS/ecs-object-client-java that referenced this issue Aug 26, 2021
…adle 6+ will have issues with JAXB resolution, causing confusing errors in their applications
twincitiesguy added a commit to EMCECS/ecs-object-client-java that referenced this issue Aug 26, 2021
…adle 6+ will have issues with JAXB resolution, causing confusing errors in their applications
twincitiesguy added a commit to EMCECS/atmos-client-java that referenced this issue Sep 9, 2021
…j/dom4j#99) that causes SAX parsing issues for consumers using Gradle 6+
twincitiesguy added a commit to EMCECS/atmos-client-java that referenced this issue Sep 9, 2021
…j/dom4j#99) that causes SAX parsing issues for consumers using Gradle 6+
@hoangcongtuan
Copy link

I have try and got an error at runtime

image

2022-08-01 08:36:09.183 6826-6826/com.xxx.dev E/AndroidRuntime: FATAL EXCEPTION: main Process: com.xxx.dev, PID: 6826 java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jaxen/dom4j/Dom4jXPath; at org.dom4j.xpath.DefaultXPath.parse(DefaultXPath.java:353) at org.dom4j.xpath.DefaultXPath.<init>(DefaultXPath.java:59) at org.dom4j.DocumentFactory.createXPath(DocumentFactory.java:222) at org.dom4j.tree.AbstractNode.createXPath(AbstractNode.java:202) at org.dom4j.tree.AbstractNode.selectNodes(AbstractNode.java:159) at xxx(my app package) at xxx(my app package) at xxx(my app package) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42) at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664) Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@48d11a8, Dispatchers.Main.immediate] Caused by: java.lang.ClassNotFoundException: Didn't find class "org.jaxen.dom4j.Dom4jXPath" on path: DexPathList[[zip file "/data/app/~~iRsRncGn8L063hNDpVm64A==/xxx-PpfNVzHq5gt0ms5r9BNdZQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~iRsRncGn8L063hNDpVm64A==/xxx-PpfNVzHq5gt0ms5r9BNdZQ==/lib/arm64, /data/app/~~iRsRncGn8L063hNDpVm64A==/xxx-PpfNVzHq5gt0ms5r9BNdZQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) ... 16 more

@Vampire
Copy link

Vampire commented Aug 1, 2022

They are optional dependencies, not unnecessary dependencies. If you use the part that needs that dependency, you also need the dependency.

The quick and easy way is to add it as runtimeOnly dependency.
The semantically correct way would be to - either in the same or another component metadata rule - add a variant for that use-case and then depend on that variant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

5 participants