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.
170 stars 57 forks source link

Can a sub project be a root project as well? Can settings.gradle be set for such a project so it can be run separately? #397

Open martinsasek opened 6 years ago

martinsasek commented 6 years ago

I have a following setup (maybe not that clever...) project1 [root] project2 [subproject or project 1, but originally it was a separate project and can be run separately] project3 [subproject of both project 1 and project 2]

My issue is that when I try to run project 2, it runs with settings.gradle from project 1 - the "-c, ....\project1\settings.gradle" argument is added automatically when the run task is performed on project2.

When I try to add "-c, ....\project2\settings.gradle" to the configuration of project2 in Project Properties ->Built-In Tasks -> -> Run -> Arguments the build fails because the -c argumets is added 2 times both for project 2 and project 1.

Can I bypass this auto adding of settings.gradle from project 1 somewhere? Or it is a built-in behavior of the gradle plugin and I have to change my project setup?

Or maybe the problem is just that the build.gradle of the project1 that is also executed? Because the build fails when running project2 with settings.gradle of project1 with an error message that it cannot find main class of project1

Thanks a lot for help.

Hillkorn commented 6 years ago

settings.gradle is a special file that tells gradle where the root level of your project is but you can disable the search for it but as I read the current doc it's marked as deprecated -u, --no-search-upward (deprecated) Don’t search in parent directories for a settings.gradle file. The problem you have I think is that you complain about the parallel execution of the same task name in multiple projects if you are on the root and just run 'gradle taskName -c ...' which you can easily fix by setting the absolute task path like 'gradle project2:taskName -c....'

martinsasek commented 6 years ago

Thank you Hillkorn, I think this solution would work if I was running gradle from command line and not using the Run button in NetBeans (or the associated keybord shortcut), am I right? Netbeans even seems to call gradle in the way you suggest when I use the Run button: Executing: gradle :project2:run Arguments: [-PcmdLineArgs=, -PjvmLineArgs=, -c, ...\project1\settings.gradle]

The problem is that it automatically adds the [-c, ...\project1\settings.gradle] arguments and I don't know where to change that.

kelemen commented 6 years ago

If you would close project1 (and if project2 has its own settings.gradle), then NB should no longer add project1's settings.gradle. This automatic adding of "-c" was added to support other exotic use-cases.

However, the question is why does your build fails when run with project1 as a root project. That is, why is it in its settings.gradle if it does not actually support it?

That said, it might be reasonable to check if you have explicitly set "-c" and then NB would not specify it explicitly.

martinsasek commented 6 years ago

Thank you for reply, kelemen and sorry for not replying so long.

If you would close project1 (and if project2 has its own settings.gradle), then NB should no longer add project1's settings.gradle. This automatic adding of "-c" was added to support other exotic use-cases.

This is not true in my case, when I close project1 and either run or run tests or run intallDist task in all cases NB automatically add this "-c"

However, the question is why does your build fails when run with project1 as a root project. That is, why is it in its settings.gradle if it does not actually support it?

The build seems to fail because not only it loads the project1's settings.gradle but also it's main class and this is, I think, because it runs also build.gradle for project1. Also when installDist for project2 is run it copies some config files into the project1 folder and not into project2 folder as it should.

That said, it might be reasonable to check if you have explicitly set "-c" and then NB would not specify it explicitly.

When I try to set this "-c" explicitly via Run ->Set project configuration -> Customize -> Built-In Tasks -> either Run or Test and Adding to Arguments window -c .\settings.gradle Then the task fails with: "Problem with provided build arguments: Problem with provided build arguments: [-PcmdLineArgs=, -PjvmLineArgs=, -c, .\settings.gradle, -c, D:...\project1\settings.gradle, --init-script, C:\Users\martin.sasek\appdata\Local\Temp\nb-gradle-plugin-martin_sasek\task-init-script-baafd7b96b031d62cb99589c041343e5.tmp] . Multiple arguments were provided for command-line option '-c'"

When I run either installDist or Run in gradle outside NB these problems don't appear, but outside netbeans I have Gradle 2.12 while inside I have 4.5.1 I guess - so maybe here is some difference? Maybe the problem is that I am using Netbeans 8.1 and I should upgrade NB to at least 8.2?

UPDATE: updated gradle outside netbeans to 4.10.2 and Netbeans to 8.2 and the behavior is still the same

Hope I was clear in my replies and thanks for help.