Structure101 Workspace IntelliJ IDEA and Gradle

The IDEA gradle import creates module compile output paths that are different to the gradle build output paths. Structure101 Workspace uses the IDEA module compile output paths to find the bytecode. So, running a gradle build will not propagate changes to the code into the Structure Map.

A workaround is to run the IDEA build to generate bytecode into the module compile output paths. But this only works if the setting “Delegate IDE build/run actions to gradle” (under Project Settings | Build, Execution, Deployment | Build Tools | Gradle | Runner) is unchecked. And it is not ideal since there are two sets of bytecode generated.

An alternative solution is to use the gradle Idea plugin to override the module compile output paths when the project is imported into IDEA.

Import your gradle project into IDEA in the usual way. You can use either the file or folder based format for the project

If you check “Create separate module per source root” in the import dialog the import will create IDEA modules for each source root in the gradle module. The module names will be suffixed, usually with _main and _test. Having separate modules for test code is useful when extracting modules from the monolith. (After the import completes you can toggle this setting off and on in the gradle settings dialog)

The separate test modules allow the test code to be excluded from the Structure Map by adding excludes in the Structure101 Workspace settings dialog (<module_name>.*). This patterns excludes the code and the module from the Structure Map.

After import the module compile output paths will be set to the gradle output paths that you added to the build.gradle file. Building with gradle at the command line will now update the bytecode that Workspace is referencing.

If you wish to trigger the gradle build using the IDEA build commands the “Delegate IDE build/run actions to gradle” setting can be checked.

Update:

The latest version of the Workspace plugin for IDEA now has an additional option on the settings page.

Include ‘Test Source Folders’ when populating Structure Map

This option is off by default. Any code marked as test in the IDEA module settings Sources tab (see below) will not be included in the Structure Map model if this new option is unchecked. When checked, additional top level modules will be created in the Structure Map containing test code. These modules will have the same name as the main module with the configurable suffix (-test by default).

Note that a Studio project created from the Workspace .hsw file will show the same modules as Workspace. So if the Test option is checked then Studio will also show the test modules.