As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.


Here are some tips for How to share your SAS knowledge with your professional network.


User talk:Nicolekristen

From sasCommunity
Jump to: navigation, search

How to specify Java Source and Target Compatibility in a Gradle multi project

I have a multiple project setup and I want to build top level projects using different JDKs.

I did some experiments by myself and the following configuration worked for me (using gradle 3.1 and the wrapper function).

At the root level my gradle.properties file looks like this:

org.gradle.daemon=true

JDK7_HOME=/usr/lib/jvm/jdk-7-oracle-x64

JDK8_HOME=/usr/lib/jvm/oracle-java8-jdk-amd64

Default JDK should be JDK 7. So I defined this in my root build.gradle file

...

 subprojects {

   apply plugin: 'java'
   sourceCompatibility = 1.7
   targetCompatibility = 1.7

   compileJava.doFirst {
     println 'source compatibility: ' + sourceCompatibility
     println 'targetCompatibility: ' + targetCompatibility
   }

   tasks.withType(JavaCompile) {
     if (project.hasProperty('JDK7_HOME')) {
       options.fork = true 
       options.bootClasspath = '$JDK7_HOME/jre/lib/rt.jar:$JDK7_HOME/jre/lib/jce.jar'
     }
   } 

   test.doFirst { 
     println 'executing tests with JDK ' + test.executable 
   } 

   tasks.withType(Test) { 
     if (project.hasProperty('JDK7_HOME')) {
       test.executable = '$JDK7_HOME/bin/java'
     }
   }

} ...

With this configuration the source and target compatibility is now set to 1.7 for every sub project. I use compileJava.doFirst and test.doFirst to verify that everything works as expected. Now, in my sub project B I want to use Java 8. The following did the trick: build.gradle

... tasks.withType(JavaCompile) {

 if (project.hasProperty('JDK8_HOME')) {
   sourceCompatibility = 1.8
   targetCompatibility = 1.8
   options.fork = true
   options.bootClasspath = '$JDK8_HOME/jre/lib/rt.jar:$JDK8_HOME/jre/lib/jce.jar';
 }

}

tasks.withType(Test) {

 if (project.hasProperty('JDK8_HOME')) {
   test.executable = '$JDK8_HOME/bin/java'
 }

} ...

That it’s. I hope this has helped you.

Welcome! and is the above material SAS-related?

Hi, Nicolekristen, and welcome to our community! I do want to note that according to our terms of use, content posted in our community must be SAS-related. While the above section relates to programming, I'm not sure sasCommunity.org is the ideal place for it.

Are you a SAS user? Can you explain how the above code helps you in working with some SAS product? If you answer yes to both questions, I would encourage you to be more clear when posting content here. If not, I'd recommend finding another community (though by all means stick around if you're interested in learning more).

If you would like to discuss further, or are seeking any help editing content, feel to comment here or on my talk page. = paulkaefer (talk) 08:32, 18 August 2017 (CDT)

Given the subsequent actions of this user, I suspect the above content is wiki spam and ought to be removed, or at least moved to the user's User page, to make it easier to discuss this user's behavior. - Cameron (talk) 15:11, 29 August 2017 (CDT)
The one link in the above text does not link to a website with any obvious SAS association. Given that, I believe the text is a breach of the terms of use and ought to be removed, until the user can put up a convincing argument to retain it. The text itself is not understandable without knowing its wider context. - Cameron (talk) 16:58, 31 August 2017 (CDT)
I believe the above content is from the article "How to specify Java Source and Target Compatibility in a Gradle multi project" by Claudio Altamura. That makes it a copyright violation and subject to removal. - Cameron (talk) 03:24, 7 September 2017 (CDT)

Inappropriate Content

Hi Nicolekristen,

I think the content that you have posted here and there is not appropriate for Talk:Main Page or any other talk page. If you are wanting to contribute an article then you should Create an Article, rather than use talk pages. But be warned anything you contribute will be edited mercilessly and Do not submit copyrighted work without permission! I have removed the work that you have recently posted because it is not obvious that you have permission to use it as it is signed with a different user name. If you didn't write it, please supply evidence that you have the original author's permission to use the work. If you did write it please provide a link to where this work was originally published and demonstrate that you and the original author are the same person. - Cameron (talk) 15:06, 29 August 2017 (CDT)