iamsanjay commented on PR #2682:
URL: https://github.com/apache/solr/pull/2682#issuecomment-2404936521

   The toolchain cannot be set at the JavaCompile level. Because we are using 
different Jdk for main and test package. To set at project level, below is the 
config. But this fails!
   
   ```
   allprojects {
     plugins.withType(JavaPlugin) {
       java {
       toolchain {
           languageVersion = JavaLanguageVersion.of(17)
       }
     }
    }
   }
   ```
   
   Next, we have different toolchain for the tasks. And below is the way to 
configure different toolchain for compileJava and compileTestJava.
   
   ```
   tasks.withType(JavaCompile) {
           compileTestJava {
             javaCompiler = javaToolchains.compilerFor {
               languageVersion = 
JavaLanguageVersion.of(JavaVersion.toVersion(scriptDepVersions['min-java-version']).toString())
             }
             options.compilerArgs += ["--release", 
JavaVersion.toVersion(scriptDepVersions['min-java-version']).toString()]
           }
           compileJava {
             javaCompiler = javaToolchains.compilerFor {
               languageVersion = 
JavaLanguageVersion.of(project.minJavaVersion.toString())
             }
             options.compilerArgs += ["--release", 
project.minJavaVersion.toString()]
           }
         }
   ```
   
   This works! I ran with `./gradlew :solr:api:build --info` and I can see 
different toolchain being loaded
   
   ```
   Task ':solr:api:compileJava' is not up-to-date because:
     Output property 'destinationDirectory' file 
/Users/sanjaydutt/Documents/solr/solr/api/build/classes/java/main has been 
removed.
     Output property 'destinationDirectory' file 
/Users/sanjaydutt/Documents/solr/solr/api/build/classes/java/main/org has been 
removed.
     Output property 'destinationDirectory' file 
/Users/sanjaydutt/Documents/solr/solr/api/build/classes/java/main/org/apache 
has been removed.
     Output property 'options.generatedSourceOutputDirectory' file 
/Users/sanjaydutt/Documents/solr/solr/api/build/generated/sources/annotationProcessor/java/main
 has been re
   moved.
   The input changes require a full rebuild for incremental task 
':solr:api:compileJava'.
   Full recompilation is required because no incremental change information is 
available. This is usually caused by clean builds or changing compiler 
arguments.
   Compiling with toolchain 
'/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home'.
   Compiling with JDK Java compiler API.
   Class dependency analysis for incremental compilation took 0.003 secs.
   Created classpath snapshot for incremental compilation in 0.0 secs.
   work action resolve main (project :solr:api) (Thread[#760,Execution worker 
Thread 3,5,main]) started.
   Resolve mutations for :solr:api:processResources (Thread[#760,Execution 
worker Thread 3,5,main]) started.
   
   
   > Task :solr:api:compileTestJava
   Caching disabled for task ':solr:api:compileTestJava' because:
     Build cache is disabled
   Task ':solr:api:compileTestJava' is not up-to-date because:
     Task has failed previously.
   The input changes require a full rebuild for incremental task 
':solr:api:compileTestJava'.
   Full recompilation is required because no incremental change information is 
available. This is usually caused by clean builds or changing compiler 
arguments.
   Compiling with toolchain 
'/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home'.
   Compiling with JDK Java compiler API.
   Class dependency analysis for incremental compilation took 0.0 secs.
   Created classpath snapshot for incremental compilation in 0.003 secs.
   Resolve mutations for :solr:api:analyzeTestClassesDependencies 
(Thread[#757,included builds,5,main]) started.
   ```
   
   #### However, jar task is still, I think ,running with whatever java_home is
   
   Because whenever I open MANIFEST.MF, Build-JDK is 21. I mean we are 
successfully able to compile files using jdk 17, however whenever jar task is 
running it's running via 21.
   
   ```
   Specification-Title: Apache Solr Search Server: api
   X-Compile-Source-JDK: 17
   X-Compile-Target-JDK: 17
   X-Build-JDK: (21.0.3)
   X-Build-OS: Mac OS X aarch64 14.3
   ```
   
   I try to add the toolchain config to `jar-manifest.gradle`, but it's not 
working
   
   ```
   doFirst {
                       def toolchain = javaToolchains.compilerFor {
                           languageVersion = 
JavaLanguageVersion.of(project.minJavaVersion.toString())
                       }
                   }
                   manifest {
                       attributes([
                               "Extension-Name"        : implementationTitle,
   
                               "Implementation-Vendor" : "The Apache Software 
Foundation",
                               "Implementation-Title"  : implementationTitle,
                               "Implementation-Version": implementationVersion,
   
                               "Specification-Vendor"  : "The Apache Software 
Foundation",
                               "Specification-Version" : project.baseVersion,
                               "Specification-Title"   : title,
   
                               // Evaluate these properties lazily so that the 
defaults are applied properly.
                               "X-Compile-Source-JDK"  : "${-> 
project.sourceCompatibility}",
                               "X-Compile-Target-JDK"  : "${-> 
project.targetCompatibility}",
   
                               "X-Build-JDK"           : 
"${System.properties['java.version']} (${System.properties['java.vendor']} 
${System.properties['java.vm.version']})",
                               "X-Build-OS"            : 
"${System.properties['os.name']} ${System.properties['os.arch']} 
${System.properties['os.version']}"
                       ])
                   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to