1

Can I possibly make Gradle compile one part of my app for Java version 1.8 and the other for 1.7? My situation is I'm writing a library, part of which will be used in a project where the version is 1.7.

I realize now that I could have broken logic in my thoughts, but the question still stands. Or, if possible, suggest something completely different.

EDIT: And if possible suggest any relevant terms, because I can't even think of a google query now.

4
  • 1
    Read about targetCompatibility: stackoverflow.com/a/44263437/750510 Commented Jun 23, 2020 at 11:25
  • IntelliJ IDEA allows you to specify per-module JDKs, so the tooling will probably support your case too. Commented Jun 23, 2020 at 11:26
  • Ok, thank you! Probably I lack different knowledge now: how to make separate modules with gradle. I'll google up on that. Commented Jun 23, 2020 at 12:21
  • 1
    guides.gradle.org/creating-multi-project-builds Commented Jun 23, 2020 at 12:31

1 Answer 1

2

Suppose you have a multi project build with the following directory structure:

  • root
    • build.gradle.kts
    • sub-project
      • build.gradle.kts
      • src/main/java
    • java-1.7-project
      • build.gradle.kts -src/main/java

Root project build file:

plugins {
  java
}

allprojects {
    group = "com.company.example"
    version = "0.0.1"

    apply {
        plugin("java")
    }

    repositories {
        mavenCentral()
    }
}

configure(subprojects.filter { it.name != "java-1.7" }) {
   java.sourceCompatibility = org.gradle.api.JavaVersion.VERSION_11
}

Java-1.7-project build file:

configure<JavaPluginExtension> {
    sourceCompatibility = JavaVersion.VERSION_1_7
    targetCompatibility = JavaVersion.VERSION_1_7
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.