kelemen / netbeans-gradle-project

This project is a NetBeans plugin able to open Gradle based Java projects. The implementation is based on Geertjan Wielenga's plugin.
172 stars 57 forks source link

Gradle project not loaded properly #372

Closed Chris2011 closed 6 years ago

Chris2011 commented 6 years ago

I opened a project, which has some gradle stuff inside. It was not created by me, it was created by a collague and I think with IntelliJ. After cloning, NetBeans can figure out, that I can open the project and it opens. I see the project with the gradle icon. The problem is, when I open the folder/package structure, there is no sources inside as you can see in my screenshot:

project-structure

But when you open files, it is already there:

files-folder-structure

I got an warning/error/exception on the project:

Failed to load the build script of the project(s):<br>org.gradle.tooling.BuildException: Could not run build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-4.1-all.zip'.<br>org.gradle.internal.exceptions.LocationAwareException: Build file 'C:\Projekte\my-service\build.gradle' line: 16
A problem occurred evaluating root project 'my-service'.<br>org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'my-service'.<br>org.gradle.api.GradleException: Nexus release user is not set!

So the Project was not opened properly. The other problem is, when I wanted to change the sources folder to get a better structure, I can't. There is no option for doing this. So I never see this project structure: http://plugins.netbeans.org/data/images/1346532324_gradle_screenshot.png

Cheers

Chris

kelemen commented 6 years ago

The problem is that NB cannot load your project at all. Given the error message, I would expect that you need to set some variables in your global gradle.properties but you should ask someone who knows the build on how to setup the project.

Chris2011 commented 6 years ago

Ok, yeah someone said that to me too, with the gradle.properties. Maybe there needs a better explanation for those, who is working for the first time. Sure I had to read stuff before, but I was wondering, I cloned the repo and it works but not as expected plus the message. Will try to fix the global variables. Thx.

kelemen commented 6 years ago

Sadly, the plugin can't really distinguish what the problem is when the build file fails to get evaluated. It would be nice if there was a standard way for the build to communicate to the IDE that "Show this message to the user" but currently there is nothing like that.

The problem you encountered is the reason I would advise everyone to never fail during script evaluation time but only when executing a task (that way, people can start working on the project easily).

Chris2011 commented 6 years ago

The thing, with the gradle.properties is one problem, correct, the other thin is that I expect, to see the right folder structure as in a java project. Why is there the gradle.properties file needed? Because there is a src/main and src/test folder so I expect to see the same structure under the project view, by default, as I've seen it in your plugin page.

kelemen commented 6 years ago

The gradle.properties is not needed by the plugin. It is needed by the build script of your project. The problem is that from the plugin point's of view, the whole build script is broken (i.e., Gradle just reports an exception and nothing else about the structure). If I was Gradle inc., I would advise officially that you shouldn't write a build script which needs some setup otherwise blows up. Though it is not the end of the world, it is discouraging (as it gives an immediate negative feedback). Some luck in your circumstance is that, even though the build blows up, NB will at least let you do some common things from the IDE like creating the global gradle.properties (by right clicking the on the Gradle home node, I probably should have also said this earlies).

Chris2011 commented 6 years ago

Yes, I did this, but in my point of view, why is the project structure broken, even when the build script or build pipeline is broken? That doesn't make sense. This will not happen to a Java or maven project afaik. If the ant script or pom.xml or whatever is broken, it will let you knows it, while build time and not while open it and to see a broken project structure. Of course, I had to fix this, because I had to add a gradle.properties file with my credentials to our company repo.

After I added this file and added my credentials, I see the correct project structure, but again, this doesn't make sense. I didn't know this, because this is not my all day work and I didn't think, that adding the global gradle.properties file, will fix the project view. Why and where should I knew this?.

kelemen commented 6 years ago

Maybe this will give you a better a understanding. This is what happens:

  1. The plugin asks Gradle to tell it the structure of the project (source folders, dependencies, etc.)
  2. Gradle evaluates the build script (because the script sets these things).
  3. During evaluating a build script, the build script code throws an exception.
  4. Gradle reports the exception to the plugin (as it could not get the project structure).

You are wrong with the Maven comparison, if you create a syntax error in the POM (say add \<X> somewhere), then you will experience something similar with a Maven project. That is, the build script throwing an exception is the equivalent of an unparseable pom.xml in the Gradle world.

As for how could you have known this: The one who wrote the build script of the project you were trying to open should have told you, as this is not something Gradle (or the plugin) requires. That is why I would recommend people to never throw an exception in the build script during evaluation time (otherwise people like you gets fooled).