Monday, August 17, 2015

Getting execution coverage in eclipse with maven m2e

Falling from cloud nine

One thing I like about eclipse and maven is that I can get the fast coding cycle in eclipse and there is a jenkins (or another CI) server running exactly the same build whenever I push my code.

So, I'm currently playing at bit around with the grpc framework implementation in Java. Creating a new maven project in eclipse and start adding the example getting started maven using the protobuf-based codegen, and it doesn't work as intended. *sigh*

Part of the offending pom below:

...
<build>
  <extensions>
    <extension>
      <groupId>kr.motd.maven</groupId>
      <artifactId>os-maven-plugin</artifactId>
      <version>1.2.3.Final</version>
    </extension>
  </extensions>
  <plugins>
    <plugin>
      <groupId>com.google.protobuf.tools</groupId>
      <artifactId>maven-protoc-plugin</artifactId>
      <version>0.4.2</version>
      <configuration>
        <!--
          The version of protoc must match protobuf-java. If you don't depend on
          protobuf-java directly, you will be transitively depending on the
          protobuf-java version that grpc depends on.
        -->
        <protocArtifact>com.google.protobuf:protoc:3.0.0-alpha-2:exe:${os.detected.classifier}</protocArtifact>
        <pluginId>grpc-java</pluginId>
        <pluginArtifact>io.grpc:protoc-gen-grpc-java:0.7.1:exe:${os.detected.classifier}</pluginArtifact>
      </configuration>
...

The problem is that the grpc code generator is build as an extension/plugin to the google proto buffer code generator, and both generators are binary native executables. To provide the correct os and platform combination it relies on the os-maven-plugin to pick the correct combo and replacing ${os.detected.classifier} in my instance with "osx-x86_64". If I run the maven build manually or insert the constant it works as intended.

m2e simply doesn't pick it up.

plugin not running in eclipse

As noted on the os-maven-plugin website itself, m2e will not use extensions defined in the file.
That is unless we tell it specifically or someone else already did as an eclipse plugin.
In the code for the plugin, there is a goal defines to run in the validation phase:

@Mojo(name = "detect", defaultPhase = LifecyclePhase.VALIDATE)

Making it explicit in the pom.xml file it will look like this:

...
<build>
 <extensions>
  <extension>
   <groupId>kr.motd.maven</groupId>
   <artifactId>os-maven-plugin</artifactId>
   <version>1.2.3.Final</version>
  </extension>
 </extensions>
 <plugins>
  <plugin>
   <groupId>kr.motd.maven</groupId>
   <artifactId>os-maven-plugin</artifactId>
   <version>1.2.3.Final</version>
   <executions>
    <execution>
     <id>detect-os</id>
     <phase>validate</phase>
     <goals>
      <goal>detect</goal>
     </goals>
    </execution>
   </executions>
  </plugin>
...

Now that m2e picks it up, we just need to tell m2e what to do with it.

m2e lifecycle-mapping

In eclipse, m2e doesn't simply run any plugin it doesn't know about. Someone need to tell eclipse that it should either run or ignore a plugin. There are several places you can do that - one of them is in the maven pom file. The problem is documented pretty well on the eclipse website under the easy to google title of Execution Not Covered, which more or less the error message eclipse will give if it doesn't know what to do with a maven plugin.

Adding an entry in pluginManagement of the build section will take care of it:

...
<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.2.3.Final,)</versionRange>
        <goals>
         <goal>detect</goal>
        </goals>
       </pluginExecutionFilter>
       <action> 
        <execute>
         <runOnConfiguration>true</runOnConfiguration>
         <runOnIncremental>true</runOnIncremental>
        </execute>
       </action>
      </pluginExecution>
     </pluginExecutions>
    </lifecycleMappingMetadata>
   </configuration>
  </plugin>
 </plugins>
</pluginManagement>

...

In the grpc case, the protoc plugin itself also needs to be added.

And that should be it! Hope it was usefull.










6 comments:

  1. Lucky Club Casino Site Review 2021
    Lucky Club Casino Review 2021 · Games: 100's of games, progressive jackpots and more · Deposit options: No, welcome bonus up luckyclub to €300 · Welcome to the Lucky Club

    ReplyDelete
  2. Casino at Mohegan Sun - Mapyro
    MapYO.com provides detailed 인천광역 출장마사지 information and road conditions for all 김천 출장안마 Casinos located in Mohegan Sun. The map shows all Casinos 청주 출장샵 and Hotels 사천 출장마사지 located 남양주 출장안마 in

    ReplyDelete
  3. Casino Royale - Live Dealer Games - Virgin Games
    Casino ventureberg.com/ Royale is a live casino with a large, eclectic portfolio of https://febcasino.com/review/merit-casino/ casino games. kadangpintar Players can play https://vannienailor4166blog.blogspot.com/ this game herzamanindir.com/ with live dealers,

    ReplyDelete
  4. With majority of casino 바카라 sport providers offering plethora of options, it is easier for gamers to take pleasure in these platforms anytime, anyplace without ready to entry their personal computer systems. The unimaginable advancement of smartphone technology has changed the lives of people in many ways. One specific area the place it has had a significant impression is playing. With mobile phones offering easy accessibility to a number of} online playing alternatives, people are transitioning from actual to virtual playing in giant numbers.

    ReplyDelete
  5. In 2017, NCAA President Mark Emmert talked about Las Vegas possibly hosting the NCAA Division I men's basketball tournament sooner or later. The United States National Football League was previously absolutely in opposition to any sort of legalization of sports activities betting prior to the late 2010s, 코인카지노 strongly protesting it as to not convey corruption into the sport. Online sports activities betting is a grey area and is not banned by any particular legislation within the Indian authorized system. That is because of|as a result of} particular provisions distinguish between games of likelihood and games of skill. One of those items lately witnessed a spike in engagement on the location throughout a shutdown in play.

    ReplyDelete
  6. With on-line casino income in 2023 being predicted to hit $92.9bn globally, it is obvious how in style these video games now are. Online slots are a serious 우리카지노 reason for this, and each sweepstakes casinos and real money sites will carry a lot to try. There actually is little question that these are a number of the} most exciting casino video games you can to|you presumably can} play across the USA.

    ReplyDelete