How can I set the compileOptions for my Gradle Java plugin?

后端 未结 4 1602
失恋的感觉
失恋的感觉 2020-12-07 00:39

I want to set the -parameters command on my gradle build so that I can use reflection to access the name of the parameters. It seems like I should be doing this with the fol

相关标签:
4条回答
  • 2020-12-07 01:18

    Please try:

    apply plugin: 'java'
    
    compileJava {
        options.compilerArgs << '-parameters' 
    }
    
    0 讨论(0)
  • 2020-12-07 01:25

    You can work with Compile Options in App.gradle file like this:

    android {
        compileSdkVersion 28
        buildToolsVersion "28.0.2"
        defaultConfig {
            applicationId "com.example.aliazaz.menuapp"
            minSdkVersion 21
            targetSdkVersion 28
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    
        /*Add Compile options in following block*/
        compileOptions {
    
            //Like these 
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    
    }
    
    0 讨论(0)
  • 2020-12-07 01:34

    You cannot overwrite all of the options (since 'options' property is read-only), but you can set them one by one. For example:

    compileJava {
        //enable compilation in a separate daemon process
        options.fork = true
    
        //enable incremental compilation
        options.incremental = true
    }
    

    Check out the docs: https://gradle.org/docs/current/dsl/org.gradle.api.tasks.compile.JavaCompile.html and https://gradle.org/docs/current/dsl/org.gradle.api.tasks.compile.CompileOptions.html

    0 讨论(0)
  • 2020-12-07 01:35
    tasks.withType(JavaCompile) {
        configure(options) {
            options.compilerArgs << '-Xlint:deprecation' << '-Xlint:unchecked' // examples
        }
    }
    

    Source: http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.compile.CompileOptions.html

    0 讨论(0)
提交回复
热议问题