0

I'm trying to create a simple maven project which compiles a .proto file and produces a .jar which can be used by other projects. My pom.xml looks like this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.iar</groupId>
    <artifactId>cspyserver-cdp</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <pluginRepositories>
        <pluginRepository>
            <id>google-protoc</id>
            <url>http://sergei-ivanov.github.com/maven-protoc-plugin/repo/releases</url>
        </pluginRepository>
    </pluginRepositories>

    <dependencies>
        <dependency>
            <groupId>com.google.protobuf</groupId>
            <artifactId>protobuf-java</artifactId>
            <version>2.5.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.google.protobuf.tools</groupId>
                <artifactId>maven-protoc-plugin</artifactId>
                <version>0.3.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Another maven project tries to refer to the classes generated by this module, using

<dependencies>
    <dependency>
        <groupId>com.iar</groupId>
        <artifactId>cspyserver-cdp</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>

This works find when I build on the command line, I can run my generated jar fine. But when I try to use this in Eclipse, the Eclipse java compiler says that it cannot resolve any of the modules generated by the protoc compiler.

I can get around this by building the maven module containing the protobuf stuff "offline" (using mvn install), and not having the project in the Eclipse workspace, but when I have both of the projects in the workspace, the protobuf classes are not found.

Something is wrong with how Eclipse detects dependencies in multi module projects, but I cannot figure out what.

2
  • Are you using m2e, i.e. standard plugin? Usually generators generate an additional src folder under target/generated-sources, which is not being included? May 27, 2014 at 13:17
  • I'm not exactly sure. Yes, I have m2e installed, and the project was created from inside Eclipse (File -> New -> Other -> Maven -> Maven Project). I don't know what other alternatives there are. How can I see if there is a source folder which isn't being included, and how do I fix it?
    – JesperE
    May 27, 2014 at 14:57

1 Answer 1

0

Try to see if you can get m2e to map the proto execution to a lifecycle..

i.e. something similar to:

<pluginManagement>
  <plugins>
    <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
    <plugin>
      <groupId>org.eclipse.m2e</groupId>
      <artifactId>lifecycle-mapping</artifactId>
      <version>1.0.0</version>
      <configuration>
        <lifecycleMappingMetadata>
          <pluginExecutions>
            <pluginExecution>
              <pluginExecutionFilter>
                <groupId>com.google.protobuf.tools</groupId>
                <artifactId>maven-protoc-plugin</artifactId>
                <versionRange>[0.3.2,)</versionRange>
                <goals>
                  <goal>compile</goal>
                  <goal>testCompile</goal>
                </goals>
              </pluginExecutionFilter>
              <action>
                <ignore></ignore>
              </action>
            </pluginExecution>
          </pluginExecutions>
        </lifecycleMappingMetadata>
      </configuration>
    </plugin>
  </plugins>
</pluginManagement>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.