netbeans 8.01 doesn't recognize gradle for webapp - netbeans

I create one web app by choosing: new project --> Java Web -> Web Application--> ....--> Spring Web MVC. Then I also want to use gradle, so I added file of build.gradle in the root of the project. Then I can see the file in "Files" tab, but can't see it in "Projects" tab. I want to see it in "Projects" tab so that I can run build command for gradle. (I added some dependency to it, but netbeans doesn't know it. I could use command line gradle to download the dependency jar, but netbeans still can't use the jar).

I know this is an old question, but the answer may still be useful to some people.
There is a plugin available for NetBeans to allow Gradle support: http://plugins.netbeans.org/plugin/44510/gradle-support
I can't see a way to show the build.gradle file in the Projects tab of your existing web project, but the Gradle plugin allows you to create Gradle projects, edit the build.gradle file in the Projects window and even launch Gradle tasks from the right-click context menu on the project node.
Gradle projects may not have some of the conveniences of NetBeans web projects, such as the Deploy option in the project node's context menu, but you can always write your own Gradle deploy task.

Related

When I create a gradle project in eclipse, there is this "lib" folder. I thought it shouldn't be here? What am I doing wrong? [duplicate]

When trying to create a gradle project in eclipse, the source folder, build.gradle and others are stored in a different folder called lib as a separate project.
How can I make all the folders be within the project folder like in a normal java project?
The problem is that the New Gradle Project dialog invokes the Gradle init task with the hard-coded argument --type java-library and that the project layout for Gradle versions higher than 6.6.1 has a lib folder besides the main project folder for a project of the type java-library (in contrast to in Gradle 6.6.1 or lower and in contrast to a project of the type application independent of the Gradle version).
In the future, in the New Gradle Project dialog, the type application should also be chooseable, to get a simple project structure like in the past. But this is not implemented yet:
Eclipse Buildship issue #1118: Add more project templates to New Gradle Project wizard
As a workaround do the following:
In the New Gradle Project dialog on the second or third page, check Override workspace settings and
choose as Specific Gradle version the version 6.6.1 and
for Java home a Java 11 JDK
In the build.gradle change id 'java-library' to id 'application'
In Project > Properties: Gradle choose a higher Gradle version
The last two steps are only required to use a Gradle version higher than 6.6.1.

Do dependencies need to be added through both the Eclipse GUI and the Gradle configuration files?

Two Gradle Git projects need to be created, within the same repository, using the Eclipse IDE. Project A depends upon a third-party library (a JAR, source code, Javadoc and natives) and project B depends upon project A.
Without Gradle, both projects would be created and Git would be enabled with Project Explorer > [Project Name] > Team > Share Project. Then, dependencies would be added via Project Explorer > [Project Name] > Build Path > Configure Build Path, followed by Projects > Add and Libraries > Add External JARs (which would also allow the specification of the locations of related source code, Javadoc and natives). This would enable automatic code completion of Project A from Project B as well as source code and Javadoc integration, within Eclipse.
With Gradle, should the settings.gradle or build.gradle files be manually edited, without adding dependencies through the Eclipse GUI, or must both be used simultaneously? Additionally,how does this effect which hidden files should be indexed by Git (.project, .classpath, .settings, .gradle)?
How is this setup through Eclipse and Gradle?
When you use a build-tool like Gradle (or maven), it is kind of assumed that the build-tool is in charge of configuring stuff like project dependencies and classpaths.
This kind of conflicts with the Eclipse UI which is kind of built to allow you to manage classpath / dependencies via its own ui.
But the Eclipse UI only controls what eclipse uses as the classpath when the Eclipse JDT compiler compiles your code... inside Eclipse.
So if you change things that way, then Gradle will not know about these dependencies and the build won't work.
Yep, this is definitely confusing :-)
The proper thing to do is manage your dependencies and project configuration entirely through gradle. So that means editing the build.gradle and settings.gradle.
The tools (BuildShip or STS Gradle Tools) provide a 'bridge' to try and configure Eclipse projects in conformance with your build.
E.g they may offer a 'Update Project' or 'Refresh Dependencies' command in project context menu.
Even if you don't use Gradle tooling, this kind of holds true. You then would use Gradle's 'ecplise' plugin and run a command like
gradle cleanEclipse eclipse
To generate the eclipse project config from the build config. Then import the project into Eclipse as configured by gradle. Also in this case, it would be a bad idea to use Eclipse UI to make changes to the buildpath since ultimately it has the same issue, changes you make to those generated files may make things compile inside Eclipse, but Gradle doesn't know you changed anything. And the next time you run gradle cleanEclipse eclipse your changes are also blown away.
As to your specific questions:
should the settings.gradle or build.gradle files be manually edited ...
Yes.
... without adding dependencies through the Eclipse GUI ...
Yes.
... or must both be used simultaneously?
No, only configure things in gradle. Then 'synch it up' to eclipse with some tool (BuildShip / STS Gradle / gradle cleanEclipse eclipse)
How does this effect which hidden files should be indexed by Git (.project, .classpath, .settings, .gradle)?
General rule of thumb. Only index the stuff that defines gradle's behaviour (there may be some exceptions, but in general try to minimize them only violate this rule if you have a good reason).
So specifically don't put in git these 'eclipse metadata'
.settings
.project
.classpath
Do put in git: the gradle wrapper and its properties file.
Gradle also has a .gradle folder. It belongs to gradle, not eclipse, buts is caches and things which are 'transient'. You don't want those in git either.

How do I refresh project dependencies using Buildship in Eclipse?

Eclipse Mars was recently released and I felt like trying it out. It listed tighter integration with Gradle as one of its features via Buildship.
With Luna I was using Gradle Integration for Eclipse (4.4) and I found this a lot easier to work with for what I was trying to do; I could add a Gradle "nature" to an existing project without needing to remove the project and re-import it as I did with Buildship, and it automatically put all dependencies that I declared in build.gradle within the project's classpath.
With Buildship, I didn't see any option to configure an existing project as a Gradle project and I couldn't find a way to make it include the dependencies I specified in the build script within the project's classpath.
I tried installing the original plugin (GIfE 4.4) for Eclipse Mars and after restarting Eclipse it automatically did all that for me again. What I'm wondering is if there's a way to do this all through Buildship alone because right now, although it all works, it's quite a funny setup. My project's dropdown menu looks like this:
Apart from looking a bit odd it is actually quite a nice setup, since it combines the automatic dependency management of GIfE with the ability to run Gradle tasks directly from Eclipse that Buildship provides.
Updating the dependencies that eclipse sees should then be as simple as:
right click on project -> gradle -> refresh all
Update in buildship 1.0.16
Currently you need to jump through the delete-and-import hoop the first time you use an existing gradle project with buildship. You can now use the Add Gradle Nature option:
right click on project -> configure -> Add Gradle Nature
“Refresh Gradle Project” is now also shown when right-clicking on any .gradle file as well as in the context menu of the Gradle editor. source
See update below However sometimes you may find that when your project was imported, it didn't get the new Project and External Dependencies classpath entry which you would normally be able to see in your Project Properties -> Java Build Path -> Libraries
If this is indeed missing, add the following to your project's .classpath file and all the gradle goodness should start working:
<classpathentry exported="true" kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
Update in buildship 1.0.16
Gradle classpath container is restored if missing
When converting an existing Eclipse Java project to Gradle, the Gradle classpath container was missing. It is now always added when a project is a Java project.
Incase for anyone, if you are not getting the
right click on project -> gradle
link after doing the steps mentioned in #PaulAdamson answer. Try this.
In your build.gradle add apply plugin 'eclipse';
Close the project in eclispe.
Run the gradle build from command line and then reopen the project in eclipse.
Now the gradle link should be available on right click.
I agree Buildship is a bit of a disaster. The documentation is extremely sparse with limited examples and minimal user guide. You would think documenting the transition from Gradle Integration for Eclipse (4.4) would be a no-brainer but I guess not. I also don't have a single clue how to use Buildship other than that I ran some tasks manually and it put fully qualified paths in my .classpath file. That's ridiculous considering many projects are shared through change control systems.
Currently there is no "Convert to Gradle project" implemented in Buildship. However, if you remove the project and reimport it using the Gradle import wizard you should see the same exact project with the proper nature and the classpath container.
On top of that, if you have a Gradle project in your workspace and update the dependencies in the build script, you can refresh the classpath container by right-clicking on the project and select Gradle > Refresh projects.
A similar problem you were facing was discussed in the Gradle forums: discuss.gradle.org/t/adding-dependencies-to-projects/10415.
We also have a bug dedicated for this feature request: bugs.eclipse.org/bugs/show_bug.cgi?id=465355. Please vote for it and share your thoughts there too.
Regarding to the documentation: It's true that we haven't provided an official documentation for the central Eclipse help system, but there are some resources explaining the current functionality:
The user documentation on GitHub
A Vogella tutorial
If you have already converted Java project to Gradle project but [RIGHT-CLICK]+Import (Then importing 'Existing Gradle Project') then your project should be of Gradle Nature.
If the project is of Gradle Nature then in .classpath file you will not see all the .jar dependencies as you see in normal java project, Instead you will see a single entry of:
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
To refresh dependencies you should do following:
[RIGHT-CLICK] + Gradle + Refresh Gradle Project
This will fix all complication issues.

How to use eclim with gradle project

My eclim setup working perfectly with eclipse project. But I want to use gradle build system.
I am working with Libgdx framework and it provide gradle templete project.
So is there any way to use eclime + eclipse + gradle
Your best bet is to check out the Eclipse Gradle plugin, although in short you can add apply plugin: 'eclipse' to your project and then run gradle eclipse from your terminal in the root folder of your project. That should generate the necessary files for Eclipse to recognize your project, although you might need to edit the .classpath file for proper autocompletions.
That will get Eclim to recognize your project with :ProjectOpen and proper autocompletion and other goodness.
The bad is that Gradle tasks and changes to your build.gradle will require manual changes to the Eclipse side of things.
Edit: There's a new plugin available for this purpose that replaces eclim for gradle projects (but is android oriented) called Vim-Grand. It's pre-alpha and you'll want the refactor branch for now, but it's working well enough for me
You should combine it with YouCompleteMe.
What I did was use the gdx-setup.jar to create my project. I then imported it into eclipse like a normal gradle project. I closed eclipse and started up elcimd. Put "let g:EclimCompletionMethod = 'omnifunc'" in my .vimrc file. Followed the elcim instructions to use :CreateProject and that was it.
This guide was really helpful: http://www.lucianofiandesio.com/vim-configuration-for-happy-java-coding
I am able to get most or all Eclim functionality working with my libgdx project this way:
create a new libgdx project with their tools
start Eclipse
Import --> Gradle Project --> Build Model per usual libgdx project creation
shut off Eclipse, start Eclim
I get organize imports, java validation, autocompletion, all the good stuff.
That said, I want to figure out how to do this all without having to use Eclipse. I think the missing piece is the Build Models functionality. Still researching ...

GWT - Refreshing changes with 'Development Mode' with Maven

If I use GWT's Development Mode with Eclipse, changes that I make in the IDE are immediately reflected in my browser upon refresh. However, I can't seem to get the same result when using the maven plugin to build. Is this possible?
Here's what I've tried:
Running gwt:run, making a change and saving it in Eclipse, refreshing the browser.
Same as above but clicked the 'restart server' button on the GWT Development Mode console.
Telling Eclipse that my project is a GWT project and configuring a Web Application, but it fails to list any Entry Point Modules for me to choose from.
'webAppCreator -templates maven com.xx.WebApp' - creates just a pom, no project (?).
The only option seems to be: stop the console, gwt:compile, gwt:run. This cycle takes minutes each time..
Any ideas on how to achieve this, or if it's even possible? Not being able to do this is really a show stopper for us adopting GWT, since we can't scrap maven.
TIA, Roy
The real answer to this question came from Thomas Broyer's comment, but I wanted to spell out all of the steps that I took for future reference:
With Maven:
Create the project using the gwt maven plugin archetype.
Move the xxx.gwt.xml file from the 'resources' tree to the 'java' tree, as recommended by Thomas.
Run 'mvn clean install' to ensure that all's well, and to generate the async classes.
To get around this issue, add this to your pom. When you change your maven dependencies you'll need to run a maven compile to get them to take in Eclipse.
With Eclipse:
Import the project into Eclipse using 'Import Existing Maven Project'
Right-click on target -> generated-sources -> gwt, and select Build Path -> Add to Build Path.
In project properties -> Google -> Web Toolkit, 'Use Google Web Toolkit' is checked.
On the same page, add your entry point modules.
In project properties -> Google -> Web Application, ensure that 'This project has a WAR directory' is checked, and the dir points to 'src/main/webapp'
Right-click on the project, select Run As -> Web Application
Ready to go!