Changing Gradle Configuration to download plugin from different pom file


(Christopher Rucinski) #1

Background

I have been trying to migrate my existing IntelliJ IDEA plugin to use Gradle. In order to do this, we have to use the Gradle IntelliJ Plugin

When I tried to add Gradle support, I kept on noticing that I was getting a bunch of unable to resolve symbol "x" issues in my build.gradle file (those are all the red in the above picture). I noticed that the dependencies were updating; however, I was getting another issue that seemed more severe.

GitHub Issue

See the below link for the issue that I submitted. It was closed due to the fix not being related to the plugin, but to Gradle configuration apparently.

Apparent Issue and Possible Fix

It was suggested that I am pointing to the wrong pom file.

I should use this …

https://plugins.gradle.org/m2/gradle/plugin/org/jetbrains/intellij/plugins/gradle-intellij-plugin/0.2.16/gradle-intellij-plugin-0.2.16.pom

…not…

https://plugins.gradle.org/m2/gradle/plugin/org/jetbrains/gradle-intellij-plugin/0.2.16/gradle-intellij-plugin-0.2.16.pom

Question

So how do I change which pom file Gradle uses to download Gradle IntelliJ Plugin v0.2.16?

I never configured anything with pom files before, and the setup tutorials for the Gradle IntelliJ Plugin never contained any information for this. I just used the provided code snippets and build my project.

Code Links

I have 2 branches. master branch has no Gradle support, while feature/add-gradle-support use the code and configurations for Gradle.

Note: Nothing in my included and excluded files links to pom files


(Tim Yates) #2

Hiya!

I cloned your project, and gave it a go and it seems to work for me.

One suggestion would be to remove the buildscript section and the duplicate plugin application.

I changed the build.gradle to:

plugins {
    id "org.jetbrains.intellij" version "0.2.16"
}

apply plugin: 'idea'

intellij {
    version 'IC-2017.2' //IntelliJ IDEA 2016.3 dependency; for a full list of IntelliJ IDEA releases please see https://www.jetbrains.com/intellij-repository/releases
    pluginName 'ChroMATERIAL'
    type 'IC'
    updateSinceUntilBuild false
}

group 'io.github.ciscorucinski.chromaterial'
version '2.0' // Plugin version

ran ./gradlew idea, opened it in IntelliJ and none of it’s red?

I’m on IntelliJ 2017.2.1 if that is the issue?

Cheers,

Tim


(Christopher Rucinski) #3

Thanks Tim for the reply. So, I modified my build.gradle file and ran the specified idea task and then reopened IntelliJ IDEA; however, everything is still the same.

Just to be clear, when you say none is red, do you mean that there are no errors (as I am using a different color scheme. The Darcula color scheme will have everything grey and underlined instead of red).

I did notice that when I reopened IntelliJ IDEA, the Gradle tool window did not have any dependencies within the main and test source sets. However, when I re-added the duplicate apply plugin: org.jetbrains.intellij line, those dependencies came back. But once I removed the line again, those dependencies stayed.

Also, I use to have intellij.version be set to IC-2016.3 and that was showing the 2016.3 dependencies correctly. Then I changed intellij.version to be set to IC-2017.2 and the dependencies changed to the 2017.2 versions. So it appears that Gradle is still working, but I have these issues all over


(Tim Yates) #4

Hiya, it looks like this:

I don’t see test and main source sets, I get loads of provided and test dependencies in the project properties -> modules view though, is this where you mean?

Can you explain what you’re seeing?


(Christopher Rucinski) #5

The picture looks great. Looks like it works perfectly. I don’t know anything about the project properties -> modules view

Here you can see multiple things…

  • Cannot resolve symbol red issues.
  • The main and test source sets.
  • The new intellij tasks from the intellij DSL, which shows the the Gradle file is being parsed.
  • The com.jetbrains.ideaIC dependency which shows that the Gradle file is being parsed.

(Christopher Rucinski) #6

Here is another picture that shows a change to the com.jetbrains.ideaIC dependency.


(Tim Yates) #7

What’s the root src folder? I don’t have that from the repo?


(Christopher Rucinski) #8

OK, I have 2 modules.

  1. ChroMATERIAL Plugin module.
  2. ChroMATERIAL source module that contains the plugin itself.

The root src folder is in ChroMATERIAL/src

I have to modify my Gradle file to indicate that change as the Gradle IntelliJ Plugin cannot build my plugin properly right now. I am not certain of how to do that just yet, but I want to fix my current issue before I make some possible wrong changes.

Here is my project structure right now…

Now, I have 6 apparent modules (I should only have 2 I believe, but the other ones keep on coming back and I don’t know why)

The 2 correct modules are the selected one (the plugin module) which is named ChroMATERIAL.
The other one is the base module which is named ChroMATERIAL Plugin.

Does this answer your question? I come from Android Studio where most of this just works.


(Tim Yates) #9

That project structure dialog looks horribly wrong… Hmmm…

Can you try removing your intellij files (*.ipr, *.iml, *.iws) from all levels, and re-create the project by simply doing “File -> Open”, and choosing the root build.gradle file?

Not sure what’s going on here, and can’t reproduce as https://github.com/ciscorucinski/ChroMATERIAL doesn’t have the same content as you are showing me…


(Christopher Rucinski) #10

Am I suppose to create a new project location? I get a directory is already taken issue when I selected the current projects directory location, but if I choose a new location, then I cannot use the Gradle wrapper


(Tim Yates) #11
  • Close IntelliJ window
  • Remove intellij files from the folder
rm *.ipr
rm *.iml
rm *.iws
  • Select File -> Open

  • Choose the build.gradle file, and click Open

  • Select “Open as Project”

  • Click “Ok” on the “Import project from Gradle” dialog

  • Wait for IntelliJ to finish parsing the script, and all should be good?

Works for me with the code from the repo on Github, but as I said, you have a different codebase to me


(Christopher Rucinski) #12

That worked to fix the red issues of mine.

I lost the plugin module as it is just a normal module now. I still have a weird looking project structure from modules that I didn’t create or configure.

In my .idea/modules.xml I have the following…

  <modules>
    <module fileurl="file://$PROJECT_DIR$/.idea/modules/ChroMATERIAL/ChroMATERIAL.iml" filepath="$PROJECT_DIR$/.idea/modules/ChroMATERIAL/ChroMATERIAL.iml" group="ChroMATERIAL" />
    <module fileurl="file://$PROJECT_DIR$/.idea/modules/ChroMATERIAL Plugin.iml" filepath="$PROJECT_DIR$/.idea/modules/ChroMATERIAL Plugin.iml" />
    <module fileurl="file://$PROJECT_DIR$/.idea/modules/ChroMATERIAL_Plugin_main.iml" filepath="$PROJECT_DIR$/.idea/modules/ChroMATERIAL_Plugin_main.iml" group="ChroMATERIAL Plugin" />
    <module fileurl="file://$PROJECT_DIR$/.idea/modules/ChroMATERIAL_Plugin_test.iml" filepath="$PROJECT_DIR$/.idea/modules/ChroMATERIAL_Plugin_test.iml" group="ChroMATERIAL Plugin" />
  </modules>

The last 2 modules (which contain ChroMATERIAL_Plugin in the path) are modules that I never specified or configured. In fact, that was the name of a previous project that I originally had before creating the ChroMATERIAL Plugin project. I don’t know if the above is related to these extra modules are not.

These modules will always come back after a little bit of time after I delete the unnecessary ones. This is also true for the related .iml files inside of .idea/modules/ChroMATERIAL/ folder.

Maybe I will try to create a new project with Gradle support from the beginning. Have a normal Gradle module with an inner plugin module with Gradle support.


(Tim Yates) #13

That looks ok to me… IntelliJ creates a module for your compile classpath (main) and one for your test classpath (test)

You can alter this on import by deselecting the “separate classpath per module” checkbox


(Christopher Rucinski) #14

OK, that is good then. I just have to figure out how to get the ChroMATERIAL module to become an IntelliJ Plugin Module, when I opened the project, it lost that


(Christopher Rucinski) #15

After I re-instantiated the ChroMATERIAL module to be an IntelliJ Plugin module, I got back all the red issues.

I assume this is a bug of some kind on the IntelliJ IDEA side. As I have said before, IntelliJ is parsing the file correctly and giving me the right dependencies, so it is reading the issue-prone file correctly.

But thanks for all your help!


(Alexander Zolotov) #16

Nothing is wrong with IntelliJ. You have to decide what project model to use: gradle or intellij one. If you’re migrating to gradle why do you need to go back to using plugin module type?


(Christopher Rucinski) #17

@zolotov I assumed I had to because I am making a plugin. It also allows me to select where the plugin.xml file is located. Also, I cannot do stuff that I could do with the plugin module type…like prepare plugin for deployment option in the menu.

Edit: Tight now, running the Gradle tasks does nothing. I know that I need to modify my build.gradle (or add one to the sub-project) and that is the reason why it doesn’t work now, but I assumed all the normal plugin options would still be available.


(Alexander Zolotov) #18

@ciscorucinski

It also allows me to select where the plugin.xml file is located.

If you process resources with Gradle, it’s not really an option, the file must be located in <resources_root>/META-INF/plugin.xml.

like prepare plugin for deployment option in the menu.

There are buildPlugin or publishPlugin Gradle tasks for that. Read gradle-intellij-plugin README to learn more about provided tasks.


(Christopher Rucinski) #19

@zolotov[quote=“zolotov, post:18, topic:23739”]
There are buildPlugin or publishPlugin Gradle tasks for that.
[/quote]

I know about those Gradle tasks, but I also know that my build.gradle setup was incomplete and that the Gradle tasks wouldn’t do anything. I assumed I would still have the menu items like all plugins did before (i.e. didn’t realize it was an all or nothing approach).

My build.gradle file is in the main project module (not my plugin module - it contains a lot of Github related content). I still need to add a build.gradle file to my sub-project (My actual plugin called ChroMATERIAL). I need to figure out what stuff goes in which Gradle file. Can I just have 1 build.gradle file total (only in my plugin module)?

I wanted to fix all my unresolved symbol issues before I did any of that listed above.