I have a project set up like this:
protos/ # protobuf files here
pom.xml # parent pom
services/common # this module generates the protobuf classes
services/mod-1 # imports common, but in intellij only protobuf classes not found
services/mod-2 # imports common, but in intellij only protobuf classes not found
My protobuf generator looks like this in services/common/pom.xl
<plugin>
<groupId>io.github.ascopes</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>3.4.1</version>
<configuration>
<protocVersion>4.31.1</protocVersion>
<!-- <protocArtifact>com.google.protobuf:protoc:4.31.1:exe:${os.detected.classifier}</protocArtifact>-->
<!-- <outputDirectory>${project.build.directory}/generated-sources/protobuf/java</outputDirectory>-->
<sourceDirectories>
<sourceDirectory>${project.basedir}/../../protos</sourceDirectory>
</sourceDirectories>
<registerAsCompilationRoot>true</registerAsCompilationRoot>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
Now when I run mvn compile
, all the modules resolve the protobuf classes and everything compiles correctly.
But in intellij, mod-1
and mod-2
cannot resolve the protobuf classes.
What am I doing wrong?
You need to tell IntelliJ to generate those classes, otherwise it won't be aware of them, even if their creation is part of the default maven lifecycle.
Right-click on the project's folder or the pom.xml, then Maven > Generate Sources and Update Folders.