You are using Testcontainers and want to have your Testcontainers database accessible directly within IntelliJ? You are tired of changing the port configuration all the time since Testcontainers chooses a random port on each startup? This plugin solves your issue.
It automatically updates the IntelliJ data source port number with the exposed random port number that Testcontainers chose on startup.
If you don't know what is Testcontainers, please check their official web page https://www.testcontainers.org/
-
Using IDE built-in plugin system:
Settings/Preferences > Plugins > Marketplace > Search for "Testcontainers Port Updater" > Install Plugin
-
Manually:
Download the latest release and install it manually using Settings/Preferences > Plugins > ⚙️ > Install plugin from disk...
For having a working plugin, there are 2 requirements;
1- The plugin expects that your application writes a log that starts with the log entry prefix (default log entry prefix is Database:
).
If you don't see any logs on your console, please check your configurations and your log level.
Example log;
2021-06-23 14:07:26.408 INFO [your-service,,] 11111 --- [ main] o.f.c.i.database.base.DatabaseType : Database: jdbc:postgresql://localhost:12345/test (PostgreSQL 10.13)
2- Copy the URL (jdbc:postgresql://localhost:12345/test
) from the console log and add it to your IntelliJ as a new data source.
For more details, please visit this page from IntelliJ.
After covering these 2 requirements, the plugin automatically will catch the log and update the matched data source URL with the Testcontainers' one.
To adjust Testcontainers Port Updater plugin settings, open IntelliJ preferences and navigate to Tools | Testcontainers Port Updater. Please be aware, settings are stored at the project level, so each project has its own settings.
Exact match
Logged data source URL and IntelliJ data source URL should be the same ignoring port part. Example match will be:
Logged data source URL:Database: jdbc:postgresql://localhost:11111/test?loggerLevel=OFF
IntelliJ data source URL:jdbc:postgresql://localhost:22222/test?loggerLevel=OFF
Everything
Before the port part (jdbc:postgresql://localhost
) should be the same for the logged data source URL and IntelliJ data source URL. Example match will be:
Logged data source URL:Database: jdbc:postgresql://localhost:11111/test
IntelliJ data source URL:jdbc:postgresql://localhost:22222/test?loggerLevel=OFF
With testcontainers=true parameter
IntelliJ data source URL should containtestcontainers=true
and before the port part (jdbc:postgresql://localhost
) should be the same
for the logged data source URL and IntelliJ data source URL. Example match will be:
Logged data source URL:Database: jdbc:postgresql://localhost:11111/test?loggerLevel=OFF
IntelliJ data source URL:jdbc:postgresql://localhost:22222/test?testcontainers=true
Plugin based on the IntelliJ Platform Plugin Template.