Skip to content

Commit

Permalink
playing around with re-adapted early-prototype declarative Gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
elect86 committed Apr 26, 2024
1 parent 1b5f12f commit 251fbe5
Show file tree
Hide file tree
Showing 33 changed files with 686 additions and 17 deletions.
6 changes: 2 additions & 4 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 31 additions & 13 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions gradle/declarative/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//import org.gradle.api.experimental.java.javaLibrary

plugins {

}

//javaLibrary {
// javaVersion = 11
//}
7 changes: 7 additions & 0 deletions gradle/declarative/buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
`kotlin-dsl`
}

repositories {
mavenCentral()
}
1 change: 1 addition & 0 deletions gradle/declarative/buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "buildSrc"
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.gradle.api.experimental.common

import org.gradle.api.artifacts.dsl.Dependencies
import org.gradle.api.artifacts.dsl.DependencyCollector
import org.gradle.declarative.dsl.model.annotations.Restricted

/**
* The declarative dependencies DSL block for an application.
*/
@Restricted
interface ApplicationDependencies : Dependencies {
val implementation: DependencyCollector
val runtimeOnly: DependencyCollector
val compileOnly: DependencyCollector
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.gradle.api.experimental.common

import org.gradle.api.artifacts.dsl.Dependencies
import org.gradle.api.artifacts.dsl.DependencyCollector
import org.gradle.declarative.dsl.model.annotations.Restricted

/**
* The declarative dependencies DSL block for a library.
*/
@Restricted
interface LibraryDependencies : Dependencies {
val api: DependencyCollector
val implementation: DependencyCollector
val runtimeOnly: DependencyCollector
val compileOnly: DependencyCollector
// CompileOnlyApi is not included here, since both Android and KMP do not support it.
// Does that mean we should also reconsider if we should support it? Or, should we
// talk to Android and KMP about adding support
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.gradle.api.experimental.java

import org.gradle.api.experimental.jvm.HasJavaTarget
import org.gradle.api.experimental.jvm.HasJvmApplication
import org.gradle.declarative.dsl.model.annotations.Restricted

/**
* An application implemented using a single version of Java.
*/
@Restricted
interface JavaApplication : HasJavaTarget, HasJvmApplication
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.gradle.api.experimental.java

import org.gradle.api.experimental.common.LibraryDependencies
import org.gradle.api.experimental.jvm.HasJavaTarget
import org.gradle.api.experimental.jvm.HasJvmLibrary
import org.gradle.api.provider.Property
import org.gradle.declarative.dsl.model.annotations.Restricted

/**
* A library implemented using a single version of Java.
*/
@Restricted
interface JavaLibrary : HasJavaTarget, HasJvmLibrary

//inline fun javaLibrary(block: JavaLibrary.() -> Unit): JavaLibrary {
// return object : JavaLibrary{
// override val javaVersion: Property<Int> = Property
// override val dependencies: LibraryDependencies
// get() = TODO("Not yet implemented")
//
// }.also(block)
//}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.gradle.api.experimental.java

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.experimental.jvm.internal.JvmPluginSupport
import org.gradle.api.internal.plugins.software.SoftwareType
import org.gradle.api.plugins.ApplicationPlugin

/**
* Creates a declarative [JavaApplication] DSL model, applies the official Java application plugin,
* and links the declarative model to the official plugin.
*/
abstract class StandaloneJavaApplicationPlugin : Plugin<Project> {
@get:SoftwareType(name = "javaApplication", modelPublicType = JavaApplication::class)
abstract val application: JavaApplication

override fun apply(project: Project) {
val dslModel = application

project.plugins.apply(ApplicationPlugin::class.java)

linkDslModelToPlugin(project, dslModel)
}

private fun linkDslModelToPlugin(project: Project, dslModel: JavaApplication) {
JvmPluginSupport.linkJavaVersion(project, dslModel)
JvmPluginSupport.linkApplicationMainClass(project, dslModel)
JvmPluginSupport.linkMainSourceSourceSetDependencies(project, dslModel.dependencies)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.gradle.api.experimental.java

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.experimental.jvm.internal.JvmPluginSupport
import org.gradle.api.internal.plugins.software.SoftwareType
import org.gradle.api.plugins.JavaLibraryPlugin

/**
* Creates a declarative [JavaLibrary] DSL model, applies the official Java library plugin,
* and links the declarative model to the official plugin.
*/
abstract class StandaloneJavaLibraryPlugin : Plugin<Project> {
@get:SoftwareType(name = "javaLibrary", modelPublicType = JavaLibrary::class) abstract val library: JavaLibrary

override fun apply(project: Project) {
val dslModel = library

project.plugins.apply(JavaLibraryPlugin::class.java)

linkDslModelToPlugin(project, dslModel)
}

private fun linkDslModelToPlugin(project: Project, dslModel: JavaLibrary) {
JvmPluginSupport.linkJavaVersion(project, dslModel)
JvmPluginSupport.linkMainSourceSourceSetDependencies(project, dslModel.dependencies)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.gradle.api.experimental.jvm

import org.gradle.api.provider.Property
import org.gradle.declarative.dsl.model.annotations.Restricted

/**
* A component that is built for a single Java version.
*/
@Restricted
interface HasJavaTarget {
@get:Restricted
val javaVersion: Property<Int>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.gradle.api.experimental.jvm

import org.gradle.api.Action
import org.gradle.api.tasks.Nested
import org.gradle.declarative.dsl.model.annotations.Configuring
import org.gradle.declarative.dsl.model.annotations.Restricted

/**
* A component that is built for multiple Java versions.
*/
@Restricted
interface HasJavaTargets {
@get:Nested
val targets: JvmTargetContainer

@Configuring
fun targets(action: Action<in JvmTargetContainer>) = action.execute(targets)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.gradle.api.experimental.jvm

import org.gradle.api.Action
import org.gradle.api.experimental.common.ApplicationDependencies
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Nested
import org.gradle.declarative.dsl.model.annotations.Configuring
import org.gradle.declarative.dsl.model.annotations.Restricted

/**
* Represents an application that runs on the JVM.
*/
@Restricted
interface HasJvmApplication {
@get:Restricted
val mainClass: Property<String>

@get:Nested
val dependencies: ApplicationDependencies

@Configuring
fun dependencies(action: Action<in ApplicationDependencies>) = action.execute(dependencies)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.gradle.api.experimental.jvm

import org.gradle.api.Action
import org.gradle.api.experimental.common.LibraryDependencies
import org.gradle.api.tasks.Nested
import org.gradle.declarative.dsl.model.annotations.Configuring
import org.gradle.declarative.dsl.model.annotations.Restricted

/**
* Represents a library that runs on the JVM.
*/
@Restricted
interface HasJvmLibrary {
@get:Nested
val dependencies: LibraryDependencies

@Configuring
fun dependencies(action: Action<in LibraryDependencies>) = action.execute(dependencies)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.gradle.api.experimental.jvm

import org.gradle.api.Named

abstract class JavaTarget(val javaVersion: Int) : JvmTarget, Named {
override fun getName(): String = "java$javaVersion"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.gradle.api.experimental.jvm

/**
* An application that runs on the JVM and that is implemented using one or more versions of Java.
*/
interface JvmApplication : HasJavaTargets, HasJvmApplication
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.gradle.api.experimental.jvm

import org.gradle.api.Plugin
import org.gradle.api.experimental.java.StandaloneJavaApplicationPlugin
import org.gradle.api.experimental.java.StandaloneJavaLibraryPlugin
import org.gradle.api.initialization.Settings
import org.gradle.api.internal.plugins.software.RegistersSoftwareTypes

@RegistersSoftwareTypes(StandaloneJavaApplicationPlugin::class,
StandaloneJavaLibraryPlugin::class,
StandaloneJvmLibraryPlugin::class,
StandaloneJvmApplicationPlugin::class)
class JvmEcosystemPlugin : Plugin<Settings> {
override fun apply(target: Settings) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.gradle.api.experimental.jvm

import org.gradle.declarative.dsl.model.annotations.Restricted

/**
* A library that runs on the JVM and that is implemented using one or more versions of Java.
*/
@Restricted
interface JvmLibrary : HasJavaTargets, HasJvmLibrary
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.gradle.api.experimental.jvm

import org.gradle.api.Action
import org.gradle.api.Named
import org.gradle.api.experimental.common.LibraryDependencies
import org.gradle.api.tasks.Nested
import org.gradle.declarative.dsl.model.annotations.Configuring
import org.gradle.declarative.dsl.model.annotations.Restricted

@Restricted
interface JvmTarget : Named {
@get:Nested
val dependencies: LibraryDependencies

@Configuring
fun dependencies(action: Action<in LibraryDependencies>) = action.execute(dependencies)
}
Loading

0 comments on commit 251fbe5

Please sign in to comment.