How to run a single file in Netbeans with Gradle? - gradle

I ported our project to gradle.
Everything runs fine, also debug.
However, sometimes I'd like to start a specific main belonging to a given class, which is different from the mainClass specified in Gradle.
How can I achieve something like that without having to modify manually everytime build.gradle?
Right click -> Run still executes the gradle mainClass..

What version of NetBeans are you running?
NetBeans 11.3 (with built-in Gradle support, not the external plugin), runs the selected file when you use the context menu as described.
It appears to inject a "runSingle" task into the Gradle project to accomplish this.

Related

IntelliJ IDEA on Mac. Is it possible to build my Kotlin Native project from the commandline without the IDE?

Quite new to all things Kotlin / IntelliJ / IDEA / gradle.
I'm comparing some code in about ten languages and the Kotlin Native version is the only one that I can't figure out how to build without using the IDE.
I started the project in IntelliJ IDEA by following guides on getting started with Kotlin and this was the recommended method.
By Googling, searching the IntelliJ help, and hunting here on StackOverflow I've been unable to find the answer. Most questions are about Multiplatform and phone apps. I'm just making a macOS commandline tool for now.
Is there a way included with IntelliJ IDEA to build a project form the terminal without starting up the IDE?
Or would it actually require me to use a completely different build system and just use Kotlin Native Mono install totally separate from the IntelliJ setup? Is no shared build system possible or would that be an even more advanced proposition?
There is no need to use the IntelliJ IDEA to build the Kotlin native project.
You should be able to use the gradle build or gradle nativeBinaries command from the Terminal to build the Gradle project.
Also, you could refer to the Kotlin native documentation here for details: https://kotlinlang.org/docs/native-gradle.html
I figured it out with a bit more trial and error.
IntelliJ IDEA seems to come with gradle but doesn't put it in the path. The IntelliJ IDEA project has set up a build system that will work with gradle as is though. You don't have to set up a new one from scratch.
In my case the gradle executable was at:
/System/Volumes/Data/Users/hippietrail/.gradle/wrapper/dists/gradle-7.4.2-bin/48ivgl02cpt2ed3fh9dbalvx8/gradle-7.4.2/bin/gradle
Running gradle using the full path with no parameters looks like it's doing something and takes a while, but doesn't build the project. To build it simply add the build parameter so in my case:
/System/Volumes/Data/Users/hippietrail/.gradle/wrapper/dists/gradle-7.4.2-bin/48ivgl02cpt2ed3fh9dbalvx8/gradle-7.4.2/bin/gradle build
It seems that gradle is not in the path by design and that the intended usage is via the gradlew that IntelliJ IDEA put in my project directory for me. This is an (explicit) wrapper script for gradle. So the more straightforward invocation is:
./gradlew build

How to make IntelliJ IDEA open Gradle's own source code?

I'm working on a Gradle plugin. Sometimes I want to look at the source code or Javadocs of Gradle's own classes. I want to do it from IntelliJ IDEA, without having to open a separate application. That is, Ctrl+click or Ctrl+B on a Gradle method or class and have IntelliJ open the source code of Gradle itself.
I have tried everything from Attaching Gradle sources in IntelliJ IDEA :
adding wrapper { ... } block in build.gradle
file gradle/wrapper/gradle-wrapper.properties has distribution type all (and, to my knowledge, has never had other distribution type on this particular machine)
I have also tried attaching sources manually by downloading Gradle source code from GitHub, but IntelliJ doesn't seem to be able to ingest it.
In addition to that, I have tried standard troubleshooting remedies of IntelliJ:
Refresh Gradle project
File > "Invalidate Caches / Restart" > "Invalidate and Restart"
Yet, when I click on method project.getProperties() (as an example), IntelliJ IDEA opens decompiled Project.class instead of the source code file Project.java.
How to make IntelliJ IDEA open Gradle's own source code?
Looks like you are facing this issue: IDEA-197970.

spring-boot-devtools doesn't reload dependent modules in multi-module maven project

Before I start, I'd like to say that I already tried the solution proposed in spring-boot-devtools reload of multi-module maven project changes, which didn't work for me.
Problem:
I have a multi-module Spring Boot project of this sort:
The module launcher has a Maven dependency on module GUI. I launch my Spring Boot application from the main method in launcher.
When I run the application and change any HTML file in GUI module, the spring-boot-devtools dependency doesn't do a live reload of these changes for my running application. Not even manual restart of launcher helps. I need to compile GUI manually and then run launcher again.
What I tried:
I tried defining the spring-boot-devtools dependency first in
parent pom.xml, then in GUI module only and then in both at the same time.
I tried adding spring.devtools.restart.additional-paths=../gui in my application.properties file as suggested in spring-boot-devtools reload of multi-module maven project changes. This does indeed trigger the reload (according to the log), but those changes just don't propagate to the jar file of GUI dependency. Also, before I even made this project into multi-module, there was no need for reloading just because of HTML files (nothing is being compiled) and I could see the changes right away.
I use Netbeans GUI if that's of any help. I also tried running the project from command line, with no success. The Maven packaging on all modules is set to jar.
The fact that this works when you configure absolute paths in devtools tells me that this is mainly a work directory issue.
So this means that:
configured paths should be relative to where you launch the CLI
you should configure the same location as a work directory in the run configuration of your IDE (whatever configuration your IDE is using to launch your application should have such an option)
In your case: everything should be relative to your launcher module; this should be as well your work directory in your IDE.
I have no idea how it happened, but upon one revisit it started working without me knowingly changing anything. It doesn't even require the spring.devtools.restart.additional-path property set.
Could've been a problem of Netbeans IDE perhaps? Then again, it didn't work from command line either. If anyone has any explanation for this, it'd still be grateful as it may prevent this problem from happening in future.

How to fix gradle eclipse plugin to use correct JRE when importing gradle project?

Currently, I can run ./gradlew eclipse and create the eclipse project and that works great in that it uses JavaSE-1.8. Unfortunately, I have 12 projects and don't really feel like loading each one at a time.
The issue though is when I use the gradle eclipse plugin and import the project, it decides to use JavaSE-1.7 which I did 'used' to use. I can't seem to find a quick setting in the gradle plugin, though it would be even nicer if I could just put the info in the build.gradle file for everyone to use.
The following code blew up in my face when I imported the project..
https://issues.gradle.org/browse/GRADLE-3100
Well, the .remove method blew up. Removing that resulted in ending up in 1.7 even though I put 1.8.
I am using gradle-2.11-bin.zip
UPDATE: I removed the '' replacing with single ' so that it doesn't throw an exception but still loads 1.7. To work around this issue, I load with gradle plugin and then run ./gradlew eclipse and then collapse all projects and using the shift key, I then select all projects and refresh and it moves to 1.8 (so the gradlew eclipse works while the gradle plugin doesn't :( they must be different code path).

How to elegantly build selected parts of a project

I have a project where I ideally wanted to be able to write something like this:
gradle build
or
gradle build -Pparts=part1,part5
Where the first command builds the whole project with a core part and all other parts. The second command builds the core part and selectively part1 and part5.
What I ended up with was splitting it up into subprojects and configuring them in the root build.gradle like this:
https://gist.github.com/Homyk/2d1d50b4678203817eaf
I can now do
gradle pack
or
gradle pack -Pparts=part1,part5
Which is fine but there are two problems at least that I would like to have solved:
I have to write a made up command instead of gradle build, which I care about because it`s open source, and I should not have to explain that.
With subprojects in Eclipse at least it`s very cumbersome to get it to build from Eclipse and develop effectively even when running 'gradle eclipse'. I ended up importing each subproject as a project which is pretty awful.
If I would solve this problem again starting from scratch what would the most elegant solution be?
Considering what you describe I would definitely go for a multi project set-up, this solves problem one as there are default ways to call only certain subprojects. More about multi-project build can be found here and a more specific StackOverflow question about executing tasks of subprojects can be found here.
I do not recognize the issues you describe in problem two. The integration in Eclipse works just fine after I installed the Gradle Integration for Eclipse Eclipse plugin from Springsource (although I have some JUnit issues). After you installed the Eclipse plugin just do the following to import the projects:
Apply the eclipse plugin to your Gradle build files.
In Eclipse open the 'Import' dialog by opening. By clicking File -> Import...
Choose Gradle Project as import source (located under the 'Gradle' category).
The 'Import Gradle Project' dialog will pup-up. Select the folder the root project is located in as root folder. Click Build Model. This should display the root project and it's subprojects. Select which project you want to import (probably all). Specify your 'Import Options' (I select everything except of the 'Use hierarchical project names'-option). Optionally add the projects to a working set. Than click Finish. The project should have been correctly imported.

Resources