Retrieve Settings Values Programmatically

Is there any way to retrieve settings values programmatically? I am developing a plugin that needs to access the user's Maven settings (specifically where their settings.xml is being defined).

I can't seem to find any way to access the value that's stored here:

Settings --> Build, Execution, Deployment --> Build Tools --> Maven

But this would really apply to any settings that the user has within their IDE.

1
8 comments
Avatar
Permanently deleted user

You are probably looking for MavenGeneralSettings.getUserSettingsFile().  

In general, each dialog that collects settings has a custom data structure backing it.  There is not a system-wide settings registry that knows about all settings for all features.

0
Avatar
Permanently deleted user

Appreciate the quick response. I assumed it would be something like that, but I don't have a "MavenGeneralSettings" class anywhere on my classpath. From what I can see that class is in the 

org.jetbrains.idea.maven.project

package...but that's not on my classpath by default using the IntelliJ JDK. I am using IntelliJ Ultimate 2017.3. From what I can see the openapi.jar and idea.jar only contain 

org.jetbrains.idea.maven.utils

and

org.jetbrains.idea.maven.aether

packages. Any idea how to get that class included?

0
Avatar
Permanently deleted user

I found it in the IntelliJ Community Edition sources, so it *should* be in one of the jars delivered with IDEA Ultimate as well.  I always manually include *every* jar in the "{idea_install_dir}/lib" directory into my IDEA SDK definitions.  Just go to the File->Project Structure...->SDK (left pane)-> {your_sdk} (mid pane)->Classpath (tab in right pane), click on the plus, and then add all of them.  (This will help when you need to run unit tests, too.)

 

0
Avatar
Permanently deleted user

Yeah, I have included all of the jars in my install directory, and it's still not showing up. I have looked for the file using CTRL+SHIFT+n, I've tried just adding the import in my class manually, I've even looked through all of the jars for that package and it's not there. As mentioned above, that entire package doesn't appear to be present...

You can also see that I have included the entire /lib/ directory of my install (although, all of the jars were already included without me explicitly doing so because the root of the SDK path points to my install location:

0
Avatar
Permanently deleted user

If you can't get hold of the classes from a jar file, you can always go download the community sources and include/copy the required classes directly into your plugin.  Or build the community sources and figure out which jar they end up in.

The community sources are at https://github.com/jetbrains/intellij-community

0
Avatar
Permanently deleted user

 

So I finally resolved this. Thank you for all of your help. In case it helps anyone else:

It turns out I wasn't including the maven plugin jar in the SDK (as mentioned by Eric in this thread)...even though it added almost every other plugin, it didn't add maven by default. So I added that:

${IDEA_HOME}/plugins/maven/lib/maven.jar

Then, I had to make sure to add this as a dependency to my plugin in the plugin.xml:

<depends>org.jetbrains.idea.maven</depends>

Once I did those things, I was able to grab the current settings by doing the following:

MavenGeneralSettings settings = MavenProjectsManager.getInstance(currentProject).getGeneralSettings();

Again, thank you Eric for all the help.

1

Is it also possible to access the Gradle settings (AS: Settings -> Build, Execution, Deployment -> Gradle)? I want to change the value of the "Use Gradle From" combobox. Thank you!

0

@Pupsicat Can be late but this is the way :

GradleSettings.getInstance(project).getLinkedProjectSettings(project.basePath!!)?.distributionType

Don't forget to add in the plugin.xml:

<depends>com.intellij.gradle</depends>

And in the gradle.properties :

platformPlugins = ....., com.intellij.gradle
0

Please sign in to leave a comment.