grails / grails-core

The Grails Web Application Framework
http://grails.org
Apache License 2.0
2.79k stars 951 forks source link

grails cli runs wrong project #12161

Open xpusostomos opened 3 years ago

xpusostomos commented 3 years ago

In the grails documentation about plugins, it suggests the following structure: https://docs.grails.org/latest/guide/plugins.html

PROJECT_DIR
  - settings.gradle
  - myapp
    - build.gradle
  - myplugin
    - build.gradle

However this is kind of inconvenient because you've got settings.gradle lost outside of any git repository, and it seems wasteful to have a repository just for one file. One might therefore suggest this structure:

PROJECT_DIR
  - myapp
    - settings.gradle
    - build.gradle
  - myplugin
    - build.gradle

gradle has a special directive for this flat structure. When using the above structure your settings.gradle would look like this:

includeFlat 'myplugin'

This will build the project fine, and one can even run it fine when one is in the myapp directory with...

gradle bootRun

HOWEVER.. if one runs from within the myapp directory...

grails run-app

instead of running myapp, it runs myplugin.. and if myplugin has its own UI, it will open the browser window displaying the myplugin UI. Then you get output on the console like this:

Running application...

Task :myplugin:bootRun

I'm not an expert on how all this works, but it seems to me if gradle bootRun is able to figure out what it's supposed to do, the fact that grails cli does the wrong thing seems like a bug to me. And there doesn't seem to be any arguments to grails run-app that would help it do the right thing either.

jeffscottbrown commented 3 years ago

However this is kind of inconvenient because you've got settings.gradle lost outside of any git repository, and it seems wasteful to have a repository just for one file.

I believe the idea is that the root of the Git repository would be the directory that includes settings.gradle, so it would not be lost outside of any git repository.

xpusostomos commented 3 years ago

@jeffbrown ... which directory do you think is the "root of the Git repository" and whose idea are we talking about? The "myapp" directory is likely to be the git root directory, because it's your app, and you aren't going to want to store plugins in the same directory within git. And that's why I'm lodging this bug report. And in terms of whose idea it is to do it which way, this is presumably what the gradle developers have thought up... it works both ways from the gradle point of view, it's just that grails doesn't seem to accept it.

jeffscottbrown commented 3 years ago

which directory do you think is the "root of the Git repository"

I am not sure I understand the question. The root directory is the top level directory of the repository.

and whose idea are we talking about?

I am not sure whose idea it was.

The "myapp" directory is likely to be the git root directory, because it's your app, and you aren't going to want to store plugins in the same directory within git.

I do that routinely. Starting with Grails 3 we have really great suport for multiproject builds and routinely setup a Git repository with any number of subprojects in it, each including a module that is part of the application, often but not always those subprojects are Grails plugins.

I really don't agree with the assertion that one wouldn't want to store plugins in the same directory within Git. This is totally routine development environment configuration and there are good reasons to organize many projects that way.

it works both ways from the gradle point of view, it's just that grails doesn't seem to accept it.

It isn't clear what Grails doesn't accept, but it definitely accepts multiproject builds. We really do do that routinely.

jeffscottbrown commented 3 years ago

I think the grails run-app problem you describe is likely a bug. Thank you for the feedback.

jeffscottbrown commented 3 years ago

The "myapp" directory is likely to be the git root directory, because it's your app, and you aren't going to want to store plugins in the same directory within git

The project at https://github.com/grails-samples/google-bookshelf is an example of a project where we do in fact have plugins in the same Git repository as the app which consumes them.

xpusostomos commented 3 years ago

I thought this was obvious, but a main reason for plugins is so that you can share those plugins with multiple apps... some of which you may 'own', and some of which may be controlled by others. Therefore, having them in the same git repository doesn't work.... This would be the case for every plugin on plugins.grails.org. And sometimes you get half way through a project, and find that the plugin on plugins.grails.org has a bug you need to fix or an enhancement you want to make, and you don't want to reorganise everything just to make a one line fix to somebody else's plugin. What you want to do is to check it out of git one level higher, add something like the:

includeFlat 'someplugin'

to your settings.gradle ... make a slight change to your build.gradle and have it work. It does seem to work for building it, but depending on various factors, if you run it, you may find yourself running the 'main' of the plugin, instead of your app. It's not clear how grails figures out which is the master app, or if you can affect that.

jeffscottbrown commented 3 years ago

I thought this was obvious, but a main reason for plugins is so that you can share those plugins with multiple apps

For some plugins that is true but we build many applications that are composed of plugins that are not shared with multiple apps. Composing a monolith into a "modular monolith" in this way has a bunch of benefits.

No one is saying that every plugin should be in a Git repo along with an app. I was simply addressing your claim:

you aren't going to want to store plugins in the same directory within git

Which is not true. We do in fact want to do that and do it frequently, and the docs describe how to do that.