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.

Add the following to the root build.gradle file: –
(Use directory names appropriate for your gradle build)

apply plugin: 'idea'

subprojects {
  idea {
   module {
     outputDir file("$buildDir/classes/java/main")
     testOutputDir file("$buildDir/classes/java/test")
     inheritOutputDirs = false
  }
 }
}


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.

2 Comments

  1. Marcel Baumann

    You could also start to support Gradle for Java, being the second most popular build tool in the Java world.

    • Paul Hickey

      Hi Marcel,

      In fact, if you install the Structure101 IDEA Connector plugin, it will create a .hsw file when you run a build in IDEA. The .hsw can then be loaded into Structure101 Studio, and can be referenced in your structure101-build-config.xml that you pass to Structure101 Build.

      I hope that helps. If you have any further questions please mail us on support@.

      Thanks for your feedback.

      best regards,
      Paul

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.