0

I have a maven multi module groovy project. When I run a main method in a groovy class thats in one of the submodules, intellij is not re-compiling before running it. It always runs the version last compiled when I manually initiated maven:compile. I don't recall having to do this manually or set any special intellij project settings in the past for this to work.

I've tried reimporting my project, several incarnations of updates to my poms, and then ultimately I had to create a run configuration where I specify a "Before Launch" configuration that executes mvn compile first. This just seems like a hack though. Its unclear to me if my issue is in a poorly constructed set of poms or if I'm truly missing some intellij configuration.

This works the first time

class MyClass2 {
  static void main(String... args) {
    print("foo")
  }
}

but if I add another print statement such as printing bar, the output of the program only prints foo and not foo and bar.

class MyClass2 {
  static void main(String... args) {
    print("foo")
    print("bar")
  }
}

My module structure is like this:

my-project
  module-1
    src/main/groovy/com/foo/MyClass2.groovy (Depends on Module1)
  module-2
    src/main/groovy/com/foo/MyClass1.groovy

My pom file for this submodule has this build section:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.gmavenplus</groupId>
            <artifactId>gmavenplus-plugin</artifactId>
            <version>1.7.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>addSources</goal>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

I can add more pom config if the problem is rooted there or provide screenshots of intellij config. I suspect intellij is the root of the problem because mvn compile and mvn clean install works just file at the parent as well as all submodules. I have no issues referencing MyClass1 from MyClass2; dependencies seem to be setup correctly.

Damon
  • 305
  • 1
  • 5
  • 13

1 Answers1

0

Verify that you have Build step in Before launch section of Run Configuration added:

enter image description here

Andrey
  • 15,144
  • 25
  • 91
  • 187
  • Thank you. I'm thinking you meant Build step and not Make, as Im not using Makefiles. I do have the build step present in the Run configuration. Is that what you meant? Above Id mentioned needed to additionally add mvn install as well. It feels like I'm missing some sort of default behavior here. I've never had this issue with java projects that use maven. Beginning to suspect Gmaven / intellij used together. – Damon Jun 27 '19 at 11:10