Skip to content

Add API to configure Gradle extensions #1530

@mhalbritter

Description

@mhalbritter

While looking at #1495 i noticed that there's currently no nice option to configure Gradle extensions.

This

kotlin {
	compilerOptions {
		jvmTarget = JvmTarget.JVM_1_8
		freeCompilerArgs += '-Xjsr305=strict'
	}
}

requires fiddling with GradleBuild.snippets() and manually constructing the coirrect syntax. It would be nice if GradleBuild could offer an API to to do that more nicely.

Maybe something like this?

build.extensions().customize("kotlin", (kotlin) -> kotlin.nested("compilerOptions", (compilerOptions) -> {
  compilerOptions.attributeWithType("jvmTarget", getJvmTarget(), "org.jetbrains.kotlin.gradle.dsl.JvmTarget");
  if (!CollectionUtils.isEmpty(this.settings.getCompilerArgs())) {
    compilerOptions.invoke("freeCompilerArgs.addAll", quote(this.settings.getCompilerArgs()));
  }
}));

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions