I’m attempting to begin using gradle by converting an existing pom using the gradle init tool, but I’m receiving an NPE. Here is the output of gradle init --stacktrace --debug.
https://pastebin.com/c4C8ruVh (I am a new user so I can’t upload, and this is way longer than the length limit allows. )
I can’t provide the source since we are closed, source, but I can say we’re using a BOM. What steps should I take to figure out what is causing the NPE? WIll I just have to convert the pom by hand? I’m completely new to gradle so I’m not sure where to start.
I’m not sure how to fix the NPE but a possible workaround is to generate an effective pom via the help:effective-pom mojo and then run gradle init on the effective pom.
This should “denormalise” any <dependencyManagement> declarations in your poms which you suspected might be causing the NPE
For a multi-module maven build there might be an extra step to split the single effective pom xml file into one per module prior to running gradle init (effective-pom will nest <project> within <projects> in this case)
Dang, it is a multi-module maven project so I got the effective pom, pulled out the different projects and pasted them into their respective existing pom (i’m seeing problems with reportPlugins but I’m ignoring those) but when I run gradle init I still get the NPE error.
From the log it looks like /Users/tylerthrailkill/Documents/dev/code/server/pom.xml is the problem. Maybe you can remove portions of it to isolate the issue.
@Lance@bmuschko Got it to work! The solution was a combination of your two suggestions. Convert project to effective pom, replacing each pom with their respective from the effective pom. Then I kept getting the NPE, so I just kept removing parts of a single pom until it worked.
Turns out that the effective pom kept a reference to the parent pom and so it was always breaking looking for the parent pom. Not sure why it was an NPE, but I was successfully able to convert most of the pom over to gradle!
Thanks guys!
Glad to hear that. I think it would still be great if we could identify why the Gradle code was failing specifically. Do you think you could put together a simplistic example that produces the issue? Also, if you feel super ambitious I’d welcome a fix for this issue so other users don’t run into the same problem.
You could simply remove <parent> from the effective pom if that’s causing issues. Effective pom duplicates anything in the parent pom in its children so it’s redundant
that does sound similar to the problem. From what I understood, gradle would look at the m2 settings.xml to find the repositories to look in. ideally it would see that parent pom in the local repository and be able to use it. If anything the error message needs to be improved.
I’m attempting to test gradle build times against our current maven build times to see whether it’s feasible to switch. I was hoping to use nebula dependency recommender to continue to have a BOM.
FWIW I’m currently working on a gradle plugin which invokes mvn help:effective-pom at build time then uses a freemarker template to generate gradle files which are then applied. It’s all dynamic and only runs on-demand (ie if maven poms change).
In theory you can run gradle and maven builds in parallel until you switch to gradle by copy/pasting the dynamically generated gradle files into your build.gradle and ditch maven for ever!
If you wanted to generate nebula dependency recommender code from maven poms it’d likely work with a custom freemarker template.
I’ll post back here when I’ve got something worth sharing if you’re interested