xolstice / protobuf-maven-plugin

Maven Plugin that executes the Protocol Buffers (protoc) compiler
https://www.xolstice.org/protobuf-maven-plugin/
Other
232 stars 76 forks source link

Errors in Eclipse #10

Closed ccleve closed 7 years ago

ccleve commented 7 years ago

I'm using the plugin in Eclipse. Each time I open the Eclipse project that uses it I get pom and compile errors. If I do a full Maven build the errors go away.

The first error is on the pom:

Multiple annotations found at this line:

protoc is, in fact, properly installed, and the error goes away when I do a build.

The second error is that either Eclipse or this plugin intermittently blows away the generated files in /target/generated-sources/protobuf. It usually happens on Eclipse startup but also happens sometimes while I'm working.

I can't tell if this is a plugin bug or an Eclipse/Maven bug.

sergei-ivanov commented 7 years ago

I'll start with the second issue. I think you may need to set clearOutputDirectory to false in the plugin's configuration section. It is true by default for historic reasons.

As for the first problem, there's not enough information. I reckon it may have something to do with os-maven-plugin integration with Eclipse, because the os.detected.classifier property is populated by os-maven-plugin. At a minimum, it would be beneficial to know the version of Eclipse and take a look at your POM file.

I am not using Eclipse myself, so any support for Eclipse integration will happen on a best effort basis, but let's see if we can make sense of the error with more information at hand. It could be some trivial config issue.

ccleve commented 7 years ago

Ok. I set clearOutputDirectory false. Because the error is intermittent, it may be a while before I know it worked.

I'm using Eclipse Neon 4.6.0, which, so far as I know, is current. It's a plain vanilla install and uses the built-in m2e (Maven 2 Eclipse) plugin.

I've attached the pom. It's a zip because github won't let me attach an xml file.

pom.zip

sergei-ivanov commented 7 years ago

I reckon the way M2E works, it actually invokes Maven on changes to the project, which causes the protobuf plugin to blitz the directory with generated sources and regenerate them from scratch each time. Suppressing clearOutputDirectory should help with that (you can still do a clean build with mvn clean install).

I believe I have found the instructions that may help you overcome Eclipse integration problems: https://github.com/trustin/os-maven-plugin#issues-with-eclipse-m2e-or-other-ides

ccleve commented 7 years ago

The os-maven-plugin seems to work ok without intervention. It's correctly detecting the os and setting the variables.

I've opened and closed Eclipse multiple times and the problem has not reoccurred. Maybe clearOutputDirectory did the trick. I'll post again if it happens again.

sergei-ivanov commented 7 years ago

Please reopen this issue if the problem recurs.

ccleve commented 7 years ago

This problem is definitely still happening. It's intermittent. Has been happening when I first start Eclipse. Doing a full project build usually clears it, but not always. Sometimes happens when I add a new .proto file.

sergei-ivanov commented 7 years ago

Can you please clarify, which of the two problems are you referring to?

Can you post your current POM please (you can create a gist for that purpose, works better than attaching a zip file).

ccleve commented 7 years ago

It's actually neither problem. The ${os.detected.classifier} has always worked correctly, and it doesn't look like files are getting deleted.

This morning I'm getting it to happen reliably if I simple edit a .proto file and save it. I get an error in Eclipse on the line in the pom that says "", line 50. The error message is the same as the one in my first comment. I've just discovered that it I simply edit and save the pom, the error goes away.

Here's the pom: https://gist.github.com/ccleve/0f30a0d61ab1c0c495637b425679f413

sergei-ivanov commented 7 years ago

Well, if you are getting Missing: ---------- 1) com.google.protobuf:protoc:exe:${os.detected.classifier}:3.0.0, then the problem is with the os-maven-plugin. In that case, can you confirm that you have followed the instructions here: https://github.com/trustin/os-maven-plugin#issues-with-eclipse-m2e-or-other-ides

ccleve commented 7 years ago

Yes, I have followed the instructions. I just upgraded to 1.5.0.Final:

kr.motd.maven os-maven-plugin 1.5.0.Final

and I copied os-maven-plugin-1.5.0.Final.jar into the /eclipse/plugins directory and restarted Eclipse. Same behavior.

sergei-ivanov commented 7 years ago

I am still suspecting it is an Eclipse + os-maven-plugin problem.

Let's try a simple test. Let's add the following execution of maven-exec-plugin early enough into the build lifecycle (and let's place it before protobuf-maven-plugin in the POM). It should work in command-line mode and it is totally harmless (does not affect the existing build at all). If it generates a similar "cannot resolve the artifact" error in Eclipse, then we know it is an Eclipse problem. If it works consistently well, then the problem might be elsewhere.

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.10</version>
        <executions>
          <execution>
            <id>test-copy-protoc</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>com.google.protobuf</groupId>
                  <artifactId>protoc</artifactId>
                  <version>3.0.0</version>
                  <type>exe</type>
                  <classifier>${os.detected.classifier}</classifier>
                  <overWrite>true</overWrite>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>
ccleve commented 7 years ago

Getting the same error. Pasted the exact code above just before the protobuf-maven-plugin. Getting a warning on the first <execution> tag: "Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-dependency-plugin:2.10:copy (execution: test-copy-protoc, phase: generate-sources)"

I can reproduce the error reliably by simply editing the .proto file.

sergei-ivanov commented 7 years ago

Good grief, Maven support in Eclipse is such a royal PITA. Let's try to work around the last error by pasting the following into your POM:

<pluginManagement>
  <plugins>
    <plugin>
     <groupId>org.eclipse.m2e</groupId>
     <artifactId>lifecycle-mapping</artifactId>
     <version>1.0.0</version>
     <configuration>
       <lifecycleMappingMetadata>
         <pluginExecutions>
           <pluginExecution>
             <pluginExecutionFilter>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-dependency-plugin</artifactId>
               <goals>
                 <goal>copy</goal>
               </goals>
               <versionRange>[0.0,)</versionRange>
             </pluginExecutionFilter>
             <action>
               <execute>
                 <runOnIncremental>true</runOnIncremental>
               </execute >
             </action>
           </pluginExecution>
         </pluginExecutions>
       </lifecycleMappingMetadata>
     </configuration>
    </plugin>
  </plugins>
</pluginManagement>

If it screws up Maven integration for the project, comment it out. What we are trying to do here is to force Eclipse to invoke the dependency plugin on each incremental build. If the problem is with passing the environment properties to the plugin, then it will show up.

All in all, I am still convinced it is an Eclipse problem.

ccleve commented 7 years ago

I'm certain it's an Eclipse problem. Pasted the pluginManagement section into the pom, got same error and same behavior, made no difference. Here's the full pom now:

https://gist.github.com/ccleve/57f75e41f27ba569c93b515010ee0f59

sergei-ivanov commented 7 years ago

Can you post a screenshot of Eclipse please, with error location and error text/tooltip clearly visible?

ccleve commented 7 years ago

Pic attached. Line 108, which is covered, is "<execution>". The complete text of the error is here:

https://gist.github.com/ccleve/fa8d24dc6e52363da4b90dfc9db5dcbe

Fixed pic:

xolstice_error

sergei-ivanov commented 7 years ago

I am really afraid that I won't be able to help here. Feel free to remove any experimental rubbish we had to introduce into the POM. I think the best course of action might be in stripping it down to a small reproducible test project and reporting to the person behind os-maven-plugin. I still think that Missing: ---------- 1) com.google.protobuf:protoc:exe:${os.detected.classifier}:3.0.0 is a give-away line, which indicates that the os.detected.classifier property was not correctly expanded before passing to protobuf-maven-plugin. It obviously works on the command line, when the entire lifecycle is executed, and all build extensions are properly initialised beforehand. But does not work in Eclipse, which does things in its own peculiar way.

As a last ditch attempt to track down the root cause, can you please check that the version of Maven configured in Eclipse is relatively recent.

szab100 commented 5 years ago

I actually managed to resolve this issue with the following pom configuration:

Eclipse then runs the os-maven-detect plugin on build and resolves the os.detected.classifier property, so the protoc plugin can resolve artifact and run the os-specific protoc compiler. There is no need to copy the os-maven-detect plugin into eclipse_home/plugins.

The corresponding pom sections:

  1. os-maven-plugin definition in <build><plugins> (and remove it from <extensions>):
      <plugin>
        <groupId>kr.motd.maven</groupId>
        <artifactId>os-maven-plugin</artifactId>
        <version>1.5.0.Final</version>
        <executions>
          <execution>
            <phase>initialize</phase>
            <goals>
              <goal>detect</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
  2. m2e lifecycle mapping in <build><pluginManagement><plugins>:
        <plugin>
          <groupId>org.eclipse.m2e</groupId>
          <artifactId>lifecycle-mapping</artifactId>
          <version>1.0.0</version>
          <configuration>
            <lifecycleMappingMetadata>
              <pluginExecutions>
                <pluginExecution>
                  <pluginExecutionFilter>
                    <groupId>kr.motd.maven</groupId>
                    <artifactId>os-maven-plugin</artifactId>
                    <versionRange>[1.5.0.Final,)</versionRange>
                    <goals>
                      <goal>detect</goal>
                    </goals>
                  </pluginExecutionFilter>
                  <action>
                    <execute></execute>
                  </action>
                </pluginExecution>
              </pluginExecutions>
            </lifecycleMappingMetadata>
          </configuration>
        </plugin>
sergei-ivanov commented 5 years ago

@szab100 Let me submit a PR with part 2 of your comment above (m2e lifecycle metadata) to os-maven-plugin. In that case it will be bundled with the plugin and it won't be necessary to pollute the POM with that information. For the first part, I'll add it to the plugin documentation as a suggested workaround. That's the best I can do for Eclipse users, I am afraid.

szab100 commented 5 years ago

@szab100 Let me submit a PR with part 2 of your comment above (m2e lifecycle metadata) to os-maven-plugin. In that case it will be bundled with the plugin and it won't be necessary to pollute the POM with that information. For the first part, I'll add it to the plugin documentation as a suggested workaround. That's the best I can do for Eclipse users, I am afraid.

@sergei-ivanov That sounds great! Please update this thread when it's done, so I can test if it works that way! Would be great to avoid having this m2e lifecycle config in the main pom.

sergei-ivanov commented 5 years ago

@szab100 PR raised (see above). Feel free to test it and upvote it.

sergei-ivanov commented 5 years ago

os-maven-plugin version 1.6.1 has been released with embedded m2e metadata. Please upgrade your projects and follow the updated instructions: https://github.com/trustin/os-maven-plugin/blob/master/README.md#issues-with-eclipse-m2e-or-other-ides