How to access data sources which are in the /.idea/dataSources.xml in my custom plugin?



I would like to access and modify data sources which are defined manually in the Database Tool Window. My plugin is generated from JetBrains/intellij-platform-plugin-template. That means the development language is Kotlin. The `` is updated with;

pluginUntilBuild = 211.*
platformType = IU
platformPlugins = com.intellij.database

Since I couldn't find the correct documentation, I tried several things by my own to access data sources like;

// Method threw 'java.lang.ClassNotFoundException' exception.
// Method threw 'java.lang.ClassNotFoundException' exception.

Before going to the ugly usual XML updating way, I would like to get your opinions.
That would be really nice if you could redirect me to the up to date correct documentation.

Thanks in advance.

Comment actions Permalink

ClassNotFoundException is most probably caused by not adding `<depends>` declaration in plugin.xml, please see guide in


Please see (last comment) as starting point


Comment actions Permalink

Many thanks for your answer Yann! I updated the plugin.xml, and now it works. 

I update the data source URL like below, it works but `dataSource.delegate as LocalDataSource` says `'getDelegate()' "is marked unstable with @ApiStatus.Internal"`. Is there any other way to update the URL?

DbPsiFacade.getInstance(project).dataSources.forEach { dataSource ->
val localDataSource = dataSource.delegate as LocalDataSource
if (..some condition..) {
localDataSource.url = "jdbc:postgresql://localhost/myNewJdbcUrl"

Thanks again 🙏🏼

Comment actions Permalink

from javadoc

* The upcoming breaking change: return type will be changed to DasDataSource.
* for connection config use {@link DbDataSource#getConnectionConfig()}
* for LocalDataSource use {@link com.intellij.database.util.DbImplUtil#getMaybeLocalDataSource(DasDataSource)}
Comment actions Permalink

That helped, thanks a lot 🙏🏼


Please sign in to leave a comment.