Is there any way to set multiple module with gradle idea plugin?
Hello!
After we migrate our project to gradle project, we have encountered the problem: Project structure has been reset every time when build.gradle has been changed. However since we have some of our resources in outside of the project, we need our project structure to be kept, or we need to make gradle able to find modules.
Our project structure is like this:
Source
└Script
└Data
└Resources
└Global
Server
└build.gradle
And I want to get project structure like below. with three modules.
> Script (C:\....\Script)
> Global (C:\....\Data\Resources\Global)
> Server (C:\....\Server)
However, if I add "../Script" and "../Data/Resources/Global" in resourceDirs at ideaModule, this project structure is what I got.
> Source (C:\...\Source)
└Script
└Data
└Resources
└Global
└ and many other unwanted files & directories...
> Server (C:\...\Server)
So is there any way to setting gradle idea plugin, or build.gradle to get proejct structure as I wanted?
Or at least, is there any way to include only certain extension from resourceDirs?
请先登录再写评论。
In the title you are asking about multiple modules, but later writing about resource directories in one module:
>However, if I add "../Script" and "../Data/Resources/Global" in resourceDirs at ideaModule
What do you want to achieve?
To have multiple modules in one project - you can just add each directory you need as a separate module.
One Gradle build script - is a one module.
Sorry for confusing terms, but those terms are exactly what intelliJ shows me when I reload gradle.
What I want to do is to add resource directory out of build.gradle directory, which is Source\Script in the example. For more details with my project structure, this is what I tried:
First, I added directory to resourceDirs in ideaModule
idea {module {
resourceDirs += file('../Source/Script')
}
}
And IntelliJ generates project structure as below.
It's fine that intelliJ automatically creates new module, but the problem is that I don't want to include other files and directories in "Source" directory. The below is what I expected, and is there any way to achieve this?
Do you mean there are other non-resource file contents under the specified "resourceDirs" ? I'm afraid those files might be impossible to be excluded. However, you can try if "excludeDirs" works for you.
https://docs.gradle.org/current/dsl/org.gradle.plugins.ide.idea.model.IdeaModule.html
Yes it is also true that there are too many non-resource contents included to project module, but real problem is that IntelliJ automatically set content root to parent directory of resourceDir. (i.e. 'Data' is my resourceDir, but 'Source' is content root in my project).
It will be perfect if resourceDir be a content root itself. Is there any reason why parent directory became content root, not resource directory itself?
The external resourceDir needs to be under a content root that does not support being modified from the same build.gradle file. Probably you need an extra build.gradle file under the resourceDir.
So explicitly create extra module is the only way to do what I want. Thanks for help!