You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by mlorenzi <Mi...@phoenixspa.it> on 2008/11/07 12:57:52 UTC

Re: compiler plugin: separate test compiler configuration


Milos Kleint wrote:
> 
> well, I suppose the question was if configuring just the testCompile
> execution doesn't work.
> I suppose having a general config at sourcelevel 1.4 and then specific
> one for testCompile execution shall work.
> 

I've the same problem and I've tried this way too, but it seems it doesnt
work.
I've reduced it in a very simple pom with something like this 
(for example to configure compiler version 1.4 as default but 1.5 for test
compile):

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <compilerVersion>1.4</compilerVersion>
        </configuration>
        <executions>
          <execution>
            <id>xxx</id>
            <phase>test-compile</phase>
            <goals>
              <goal>testCompile</goal>
            </goals>
            <configuration>
              <compilerVersion>1.5</compilerVersion>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

if I try a clean test -X I see in the log that the general configuration is
used and the one in the execution is simply ignored:

[DEBUG]   (f) compilerVersion = 1.4
...
[DEBUG] -- end configuration --
[INFO] [compiler:compile]

[DEBUG]   (f) compilerVersion = 1.4
[DEBUG] -- end configuration --
[INFO] [compiler:testCompile]

I've a more complex situation in real projects where I need to configure the
compilation for integration tests with a java 1.5 compiler keeping the 1.4
for the application sources, but I'm not able to do (same problem).
Is there something wrong with my configuration or it is a bug?
Attached is the sample pom which I used for the test.
http://www.nabble.com/file/p20379248/foo-pom.zip foo-pom.zip 
-- 
View this message in context: http://www.nabble.com/compiler-plugin%3A-separate-test-compiler-configuration-tp20058021p20379248.html
Sent from the Maven Developers mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: compiler plugin: separate test compiler configuration

Posted by Oleg Gusakov <ol...@gmail.com>.
It did not work for me, and this might have been the reason.

Anyway, I changed the compiler plugin and you can now use testSource and 
testTarget withing the same execution, if you'd like to.

Thank you for the update,
Oleg

� wrote:
> Oleg Gusakov wrote:
>   
>> Such contriction will not work. The problem is in the way compiler
>> plugin is instantiated: compiler environment is created, and them the
>> same instance is reused for test-compiler, sticking to the existing
>> plugin configuration. Execution does not get a new instance of as far
>> as  can see. 
>>
>> That is why I had to enhance the configuration of compiler plugin -
>> 2.1-SNAPSHOT now accepts the "test" set of parameters; see
>> http://jira.codehaus.org/browse/MCOMPILER-83
>>     
>
> It can work, we do so for years now: http://svn.xstream.codehaus.org/browse/~raw,r=HEAD/xstream/trunk/xstream/pom.xml. The profile for JDK 5 + 6 configure the compiler plugin with a second execution to compile the JDK 5 specific stuff with source/target=1.5 while the standard execution uses source/target=1.3. The only caveat is that the entries in the excludes lists must have exactly the same number of entries. This can be used to compile main source with source/target=1.3 while the test source is compiled with source/target = 1.5:
>
> ============= %< ===============
> <plugin>
>   <groupId>org.apache.maven.plugins</groupId>
>   <artifactId>maven-compiler-plugin</artifactId>
>   <configuration>
>     <source>1.3</source>
>     <target>1.3</target>
>     <excludes>
>       <exclude>foo</exclude>
>     </excludes>
>     <testExcludes>
>       <exclude>**</exclude>
>     </testExcludes>
>   </configuration>
>   <executions>
>     <execution>
>       <id>compile-jdk15</id>
>       <configuration>
>         <source>1.5</source>
>         <target>1.5</target>
>         <excludes>
>           <exclude>**</exclude>
>         </excludes>
>         <testExcludes>
>           <exclude>foo</exclude>
>         </testExcludes>
>       </configuration>
>       <goals>
>         <goal>compile</goal>
>         <goal>testCompile</goal>
>       </goals>
>     </execution>
>   </executions>
> </plugin>
> ============= %< ===============
>
> - J�rg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>
>   

RE: compiler plugin: separate test compiler configuration

Posted by Jörg Schaible <Jo...@scalaris.com>.
Oleg Gusakov wrote:
> Such contriction will not work. The problem is in the way compiler
> plugin is instantiated: compiler environment is created, and them the
> same instance is reused for test-compiler, sticking to the existing
> plugin configuration. Execution does not get a new instance of as far
> as  can see. 
> 
> That is why I had to enhance the configuration of compiler plugin -
> 2.1-SNAPSHOT now accepts the "test" set of parameters; see
> http://jira.codehaus.org/browse/MCOMPILER-83

It can work, we do so for years now: http://svn.xstream.codehaus.org/browse/~raw,r=HEAD/xstream/trunk/xstream/pom.xml. The profile for JDK 5 + 6 configure the compiler plugin with a second execution to compile the JDK 5 specific stuff with source/target=1.5 while the standard execution uses source/target=1.3. The only caveat is that the entries in the excludes lists must have exactly the same number of entries. This can be used to compile main source with source/target=1.3 while the test source is compiled with source/target = 1.5:

============= %< ===============
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <source>1.3</source>
    <target>1.3</target>
    <excludes>
      <exclude>foo</exclude>
    </excludes>
    <testExcludes>
      <exclude>**</exclude>
    </testExcludes>
  </configuration>
  <executions>
    <execution>
      <id>compile-jdk15</id>
      <configuration>
        <source>1.5</source>
        <target>1.5</target>
        <excludes>
          <exclude>**</exclude>
        </excludes>
        <testExcludes>
          <exclude>foo</exclude>
        </testExcludes>
      </configuration>
      <goals>
        <goal>compile</goal>
        <goal>testCompile</goal>
      </goals>
    </execution>
  </executions>
</plugin>
============= %< ===============

- Jörg

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: compiler plugin: separate test compiler configuration

Posted by Oleg Gusakov <ol...@gmail.com>.
Such contriction will not work. The problem is in the way compiler 
plugin is instantiated: compiler environment is created, and them the 
same instance is reused for test-compiler, sticking to the existing 
plugin configuration. Execution does not get a new instance of as far 
as  can see.

That is why I had to enhance the configuration of compiler plugin - 
2.1-SNAPSHOT now accepts the "test" set of parameters; see 
http://jira.codehaus.org/browse/MCOMPILER-83

Thanks,
Oleg

mlorenzi wrote:
> Milos Kleint wrote:
>   
>> well, I suppose the question was if configuring just the testCompile
>> execution doesn't work.
>> I suppose having a general config at sourcelevel 1.4 and then specific
>> one for testCompile execution shall work.
>>
>>     
>
> I've the same problem and I've tried this way too, but it seems it doesnt
> work.
> I've reduced it in a very simple pom with something like this 
> (for example to configure compiler version 1.4 as default but 1.5 for test
> compile):
>
>   <build>
>     <plugins>
>       <plugin>
>         <groupId>org.apache.maven.plugins</groupId>
>         <artifactId>maven-compiler-plugin</artifactId>
>         <configuration>
>           <compilerVersion>1.4</compilerVersion>
>         </configuration>
>         <executions>
>           <execution>
>             <id>xxx</id>
>             <phase>test-compile</phase>
>             <goals>
>               <goal>testCompile</goal>
>             </goals>
>             <configuration>
>               <compilerVersion>1.5</compilerVersion>
>             </configuration>
>           </execution>
>         </executions>
>       </plugin>
>     </plugins>
>   </build>
>
> if I try a clean test -X I see in the log that the general configuration is
> used and the one in the execution is simply ignored:
>
> [DEBUG]   (f) compilerVersion = 1.4
> ...
> [DEBUG] -- end configuration --
> [INFO] [compiler:compile]
>
> [DEBUG]   (f) compilerVersion = 1.4
> [DEBUG] -- end configuration --
> [INFO] [compiler:testCompile]
>
> I've a more complex situation in real projects where I need to configure the
> compilation for integration tests with a java 1.5 compiler keeping the 1.4
> for the application sources, but I'm not able to do (same problem).
> Is there something wrong with my configuration or it is a bug?
> Attached is the sample pom which I used for the test.
> http://www.nabble.com/file/p20379248/foo-pom.zip foo-pom.zip 
>