Creating other IntelliJ projects with the gradle idea plugin
Answered
Hi there,
I'm a plugin developer and writing a custom language plugin for our internal use. There is a lot of boiler plate in setting up our projects in IntelliJ and getting people to do that for the plugin development seemed like a lot of work. Committing anything for this to VCS is a no-go, so my second option was to use the gradle idea plugin.
I was hoping to do something like:
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.palominolabs.gradle.task:gradle-git-clone-task:0.0.2'
}
}
plugins {
id 'idea'
}
apply plugin: 'idea'
import com.palominolabs.gradle.task.git.clone.GitCloneTask
task clone(type: GitCloneTask) {
description = "Clone the Repository"
group = "initialize"
dir = file("repo")
uri = "git@bitbucket.org:myrepo.git"
treeish = 'origin/master'
knownHostsPath = 'test-projects/known_hosts'
}
task createIdeaProject(type: GenerateIdeaProject) {
ideaProject = project {
jdkName = "1.8"
vcs = "git
}
ideaProject.workspace.iws.withXml { provider ->
provider.asNode().findNode("maven3 settings").setNode("override .settings location", "$PROJECT_DIR/mavenInfo/settings.xml");
)
}
I can't find any good examples of this flow, and am not sure if the gradle intellij plugin can even be used to generate external projects in this way (i.e., projects that have nothing to do with the gradle context).
I would appreciate any advice or other options.
Please sign in to leave a comment.
Using idea Gradle plugin is not recommended as it is possible that it could produce not compatible configuration. It is better to use native IDE integration with Gradle.
What exactly are you trying to do/customize? Right now unfortunately some Maven settings like user settings file location or importing settings are not designed for sharing in a team, related requests:
https://youtrack.jetbrains.com/issue/IDEA-26406
https://youtrack.jetbrains.com/issue/IDEA-97223
Please check also https://github.com/JetBrains/gradle-idea-ext-plugin plugin that allows to set many IDE-specific options via build.gradle script.
Okay so I'm trying to do the following:
I have a bunch of Maven Java projects: A, B, C, D, E.... Those are projects people develop on, and they are responsible for creating their own IntelliJ projects, etc... I do not want to to share or do anything for when people are developing on A, B, C, D, E....
I have an IntelliJ Plugin SDK Project, that is gradle based, lets call it project X, for development of project X, it can be useful to have some of our other projects to play with. It can also be useful for some specific versions of A, B, C, D or E to be checked out. It doesn't make sense to me to have people use their real workspaces for A,B, C,D, E. So what I'd like is to have a different copy of those projects that are used only for development of project X (the IntelliJ plugin). The pain point here is that there is lots to setup with these projects that is fairly annoying. So I was hoping to use the gradle idea plugin to generate the skeletal files necessary and in bulk.
So to give you an example, lets say all git projects are stored in ~/git
Right now the folder looks like this:
Now if someone goes into project-x and types say ./gradlew initializeSampleProjects
Then that gradle task would do 2 things for every set of repos defined in the build.gradle, it would check out a fresh copy, and it would generate the necessary settings so that the project could be opened automatically.
So after running the directly would look like:
The benefit of this is that now in project-X when I run ./gradlew runIde from https://github.com/JetBrains/gradle-intellij-plugin I can then open any of the existing projects in /project-X/test-projects/project-?/ and it opens out of the box, I don't have to set them up manually. These .idea folders and projects created in test-projects are just throwaways, it doesn't need to be the most robust at all.
NOTE: The fact that the projects are already checked out in ~/git before running ./gradlew initializeSampleProjects is incidental, that is not an assumption I'm baking in, the git clone would be from repos online. In theory you could just checkout project-X on a fresh machine and then do everything.
>when I run ./gradlew runIde from https://github.com/JetBrains/gradle-intellij-plugin I can then open any of the existing projects in /project-X/test-projects/project-?/ and it opens out of the box, I don't have to set them up manually.
What does not with the approach of just opening them as Gradle project (File | Open and point to build.gradle file)? IDE will generate project config files automatically.
These are not Gradle projects and aren't related to my Gradle project. These are stand alone maven projects and they need a bunch of custom setup beyond simply opening them in IntelliJ. As such I'm trying to find a programmatic way to generate the workspaces.
The same is for maven projects: IDE creates project configuration automatically for them when they are opened from pom.xml: the point is to have the behavior of a project (build, run etc) identical from command line Maven and in IDE.
And the point is that, that is not realistic. In particular custom locations for the settings.xml and repository need to be set, as well as other options in the maven tool configuration.
We plan to support Maven wrapper: https://youtrack.jetbrains.com/issue/IDEA-146205 This will eliminate the need for storing IDE-specific settings for Maven like this.
Now, you can store maven (non-idea related) settings inside ./mvn/mvn.config and ./mvn/jvm.config files.