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

Publishing broken by commit a7fb709 : Cannot get property 'group' on null object #875

Open
simon-greatrix opened this issue Jul 14, 2023 · 5 comments

Comments

@simon-greatrix
Copy link

Shadow Version

8.1.1

Gradle Version

8.2.1

Expected Behavior

Publish should not fail with a NullPointerException

Actual Behavior

> Task :generatePomFileForShadowPublication FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':generatePomFileForShadowPublication'.
> Could not apply withXml() to generated POM
   > Cannot get property 'group' on null object

With --stacktrace option:

Caused by: org.gradle.api.InvalidUserCodeException: Could not apply withXml() to generated POM
        at org.gradle.api.internal.UserCodeAction.execute(UserCodeAction.java:41)
        at org.gradle.internal.ImmutableActionSet$SingletonSet.execute(ImmutableActionSet.java:225)
        at org.gradle.internal.MutableActionSet.execute(MutableActionSet.java:41)
        at org.gradle.internal.xml.XmlTransformer$XmlProviderImpl.apply(XmlTransformer.java:187)
        at org.gradle.internal.xml.XmlTransformer.doTransform(XmlTransformer.java:158)
        at org.gradle.internal.xml.XmlTransformer.doTransform(XmlTransformer.java:146)
        at org.gradle.internal.xml.XmlTransformer.transform(XmlTransformer.java:109)
        at org.gradle.internal.xml.XmlTransformer$1.execute(XmlTransformer.java:86)
        at org.gradle.internal.xml.XmlTransformer$1.execute(XmlTransformer.java:83)
        at org.gradle.internal.IoActions$TextFileWriterIoAction.execute(IoActions.java:146)
        ... 124 more
Caused by: java.lang.NullPointerException: Cannot get property 'group' on null object
        at com.github.jengelman.gradle.plugins.shadow.ShadowExtension$_component_closure3$_closure5$_closure6.doCall(ShadowExtension.groovy:37)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Analysis

Commit a7fb709 - see a7fb709 introduced this issue.

The old code:

                project.configurations.shadow.allDependencies.each {
                    if ((it instanceof ProjectDependency) || ! (it instanceof SelfResolvingDependency)) {
                        def dependencyNode = dependenciesNode.appendNode('dependency')
                        dependencyNode.appendNode('groupId', it.group)
                        dependencyNode.appendNode('artifactId', it.name)
                        dependencyNode.appendNode('version', it.version)
                        dependencyNode.appendNode('scope', 'runtime')
                    }

In this old (working) code, the dependency node is only added when the IF statement matches.

The new code:

        final def allDependencies = project.provider {
            project.configurations.shadow.allDependencies.collect {
                if ((it instanceof ProjectDependency) || ! (it instanceof SelfResolvingDependency)) {
                    new Dep(it.group, it.name, it.version)
                }
            }
        }
...
...
...
                allDependencies.get().each {
                    def dependencyNode = dependenciesNode.appendNode('dependency')
                    dependencyNode.appendNode('groupId', it.group)
                    dependencyNode.appendNode('artifactId', it.name)
                    dependencyNode.appendNode('version', it.version)
                    dependencyNode.appendNode('scope', 'runtime')
                }

This new code introduces the bug. I had two SelfResolvingDependency instances in my configuration and these did not match the 'IF" condition and hence the closure returned a null.

When the each call loops over allDependencies the null causes an exception.

@simon-greatrix
Copy link
Author

simon-greatrix commented Jul 14, 2023

I am a Java programmer, not a Groovy programmer, but I believe the required fix is to simply change the collect to findResults in the creation of allDependencies.

@jimshowalter
Copy link

jimshowalter commented Sep 9, 2023

Ran into the exact same problem when trying to upgrade from 7.x to 8.x.

@jimshowalter
Copy link

Here's a reproducible test case (it probably could be shrunk some more, but the key point is it demonstrates the problem).

Unzip it.

cd into the project.

Execute ./gradlew generatePomFileForMavenJavaPublication

Fails with the error.

Fails with any 8.x version of shadow.

In gradle.properties, change shadowVersion to 7.1.2.

Execute ./gradlew wrapper --gradle-version=7.6.3

Re-execute ./gradlew generatePomFileForMavenJavaPublication

Works.

problem.zip

@jimshowalter
Copy link

Is there anything we can do in our Gradle configuration to work around this bug?

@Goooler
Copy link
Member

Goooler commented Jan 12, 2025

Can you try out 9.0.0-beta4?

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

No branches or pull requests

3 participants