• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Different JAVA version for Source and target in Maven build

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am trying to build my code using Maven. now I want to configure like this: my dev machine has Java 1.8 and the target WAS server has 1.7. So can I mention this 2 differnet version in pom.xml? and how?

I have tried to give :

<plugin>
       <artifactId>maven-compiler-plugin</artifactId>
       <version>3.3</version>
       <configuration>
         <source>1.7</source>
         <target>1.8</target>
...... but getting compilation error : Source and target should be same.

Please help.

Thanks,

Surodip
 
Saloon Keeper
Posts: 12147
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So why do you have source and target versions switched?

Can you post your POM and the exact error?
 
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Having source 1.7 and target 1.8 makes no sense. You're missing out on all the language features of Java 8, so why compile it for Java 8, and not for Java 7?
The other way around probably won't work properly either, because the compiler will need to take Java 8 features and convert them to Java 7 features. For some that's simply not possible (lambdas come to mind).

Just use 1.7 for both the source and the target. It doesn't matter that your development version is 1.8; the source merely means that you will not be able to use any Java 8 language features. Unfortunately it will not prevent you from using Java 8 API calls, so just make sure to not use these. (For this specific scenario, my work PC has not just Java 8 but also 7 and even 6 installed.)
 
Sheriff
Posts: 15795
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Spoor wrote:Having source 1.7 and target 1.8 makes no sense.


Actually, according to this: http://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html#options, if you specify -source of 1.7, the default value for the -target option is 1.8
 
Rob Spoor
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That makes absolutely no sense at all. Even worse, 1.8 is the default target for any source version since 1.5. So you go to all this trouble to disable all the extra features, only to be limited to a Java 8 VM where all those features are still enabled...
 
Junilu Lacar
Sheriff
Posts: 15795
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The -source option specifies the maximum version of language features supported and the -target option specifies the minimum version of the target JVM that can run the generated class files.  Any reasoning around what combinations of these options make sense should be based on this. I'm not sure if the Maven compiler plugin has its own opinions about what combinations make sense though. When I specify these options, they're always the same though so I've never encountered the OP's problem before.

So, if you have

This behavior isn't that surprising, if you think about it. But like I said, if I have 1.4 source, it makes more sense to specify a target of 1.4 as well, you just have to specify that explicitly if you're not compiling with javac 1.4 version.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic