Excluding some sources from validation?

276 views
Skip to first unread message

Osvaldo Doederlein

unread,
Mar 14, 2014, 11:53:06 AM3/14/14
to error-pro...@googlegroups.com
Problem: I have Maven projects that mix both regular code and generated code, the latter is produced by protoc and I use the build helper plugin to dynamically add that to the compiler's list of source directories. The problem then is that protoc generated code contains issues like statics accessed through instances. I know that I could just use a separate module for this generated code and then override the compiler to use regular javac there, I was just hoping to avoid this :)

Thanks,
Osvaldo

Thomas Broyer

unread,
Mar 15, 2014, 9:02:36 PM3/15/14
to error-pro...@googlegroups.com

On Friday, March 14, 2014 4:53:06 PM UTC+1, Osvaldo Doederlein wrote:
Problem: I have Maven projects that mix both regular code and generated code, the latter is produced by protoc and I use the build helper plugin to dynamically add that to the compiler's list of source directories. The problem then is that protoc generated code contains issues like statics accessed through instances. I know that I could just use a separate module for this generated code and then override the compiler to use regular javac there, I was just hoping to avoid this :)

Couldn't you use separate maven-compiler-plugin executions?

<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <executions>
    <execution>
      <id>compile-without-errorprone</id>
      <goals>
        <goal>compile</goal>
      </goals>
      <phase>compile</phase>
      <configuration>
        <includes>
          <include>**/MyProto.java</include>
        </includes>
      </configuration>
    </execution>
    <execution>
      <id>default-compile</id>
      <configuration>
        <compilerId>javac-with-errorprone</compilerId>
        <forceJavacCompilerUse>true</forceJavacCompilerUse>
        <excludes>
          <exclude>**/MyProto.java</exclude>
        </excludes>
      </configuration>
    </execution>
  </executions>
  <dependencies>
    <dependency>
      <groupId>com.google.errorprone</groupId>
      <artifactId>error_prone_core</artifactId>
      <version>1.1.1</version>
    </dependency>
    <dependency>
      <groupId>org.codehaus.plexus</groupId>
      <artifactId>plexus-compiler-javac</artifactId>
      <version>2.3</version>
    </dependency>
    <dependency>
      <groupId>org.codehaus.plexus</groupId>
      <artifactId>plexus-compiler-javac-errorprone</artifactId>
      <version>2.3</version>
    </dependency>
  </dependencies>
</plugin>

Eddie Aftandilian

unread,
Mar 17, 2014, 8:44:11 PM3/17/14
to error-pro...@googlegroups.com
Osvaldo, does Thomas's suggestion work for you?

Thanks,
Eddie


--
Googlers: This an external list. Please be careful when posting.
---
You received this message because you are subscribed to the Google Groups "error-prone-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to error-prone-dis...@googlegroups.com.
Visit this group at http://groups.google.com/group/error-prone-discuss.
To view this discussion on the web visit https://groups.google.com/d/msgid/error-prone-discuss/9258e2e5-b2b8-4e82-8333-40977d29231c%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Osvaldo Doederlein

unread,
Mar 18, 2014, 11:09:00 AM3/18/14
to error-pro...@googlegroups.com
Thank for the suggestion. It worked well, just not exactly as provided because the proto classes are used by the others so they have to be compiled first, so I just inverted things so default-compile will compile only the proto and then it works. Apparently you cannot eliminate default-compile (if you don't have an execution with that name it will run implicitly and compile everything), and default-compile always runs first regardless of ordering in the pom. I had also tried other approaches like avoiding the build-helper plugin but with bad results; as usual gotta do things the way Maven likes :)


You received this message because you are subscribed to a topic in the Google Groups "error-prone-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/error-prone-discuss/pzT45ZMCQOc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to error-prone-dis...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Osvaldo Doederlein | Software Engineer, Doubleclick Ad Exchange |  opi...@google.com

Osvaldo Doederlein

unread,
Mar 18, 2014, 1:02:27 PM3/18/14
to error-pro...@googlegroups.com
A final comment, in the end the Maven solution didn't work for me, because I'm on Eclipse and the m2e plugin doesn't understand the customized compiler settings. usually the solution for this is using an option that m2e offers to ignore specific configurations it doesn't support, so I tried to do that and then none of my code compiles from the IDE because m2e simply kills all compilation mapping instead of reverting to defaults. Will report that as a bug to m2e.

Thomas Broyer

unread,
Mar 18, 2014, 1:10:58 PM3/18/14
to error-pro...@googlegroups.com
What you should do is configure the maven-compiler-plugin from within a profile that's *not* activated in Eclipse. Here's how I do it:

  <profiles>
    <profile>
      <id>error-prone</id>
      <activation>
        <property>
          <!-- Disable in M2Eclipse -->
          <name>!m2e.version</name>
        </property>
      </activation>
      <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <artifactId>maven-compiler-plugin</artifactId>
              <configuration>
                <compilerId>javac-with-errorprone</compilerId>
                <forceJavacCompilerUse>true</forceJavacCompilerUse>
              </configuration>
              <dependencies>
                <dependency>
                  <groupId>org.codehaus.plexus</groupId>
                  <artifactId>plexus-compiler-javac-errorprone</artifactId>
                  <version>2.3</version>
                </dependency>
                <dependency>
                  <groupId>org.codehaus.plexus</groupId>
                  <artifactId>plexus-compiler-javac</artifactId>
                  <version>2.3</version>
                </dependency>
                <dependency>
                  <groupId>com.google.errorprone</groupId>
                  <artifactId>error_prone_core</artifactId>
                  <version>1.1.1</version>
                </dependency>
              </dependencies>
            </plugin>
          </plugins>

To unsubscribe from this group and stop receiving emails from it, send an email to error-prone-discuss+unsub...@googlegroups.com.

--
Googlers: This an external list. Please be careful when posting.
---
You received this message because you are subscribed to a topic in the Google Groups "error-prone-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/error-prone-discuss/pzT45ZMCQOc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to error-prone-discuss+unsub...@googlegroups.com.
--
Osvaldo Doederlein | Software Engineer, Doubleclick Ad Exchange |  opi...@google.com

Osvaldo Doederlein

unread,
Mar 19, 2014, 10:17:26 AM3/19/14
to error-pro...@googlegroups.com
This worked perfectly, great! Now I wonder why the m2e plugin has this messy system of ignoring plugins at all, if it works correctly with profiles.


To unsubscribe from this group and all its topics, send an email to error-prone-dis...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages