Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 64 additions & 2 deletions base/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import com.google.protobuf.gradle.GenerateProtoTask
import io.spine.dependency.build.JSpecify
import io.spine.dependency.lib.AutoService
import io.spine.dependency.lib.AutoServiceKsp
Expand All @@ -37,10 +38,11 @@ import io.spine.dependency.local.TestLib
import io.spine.gradle.publish.IncrementGuard
import io.spine.gradle.publish.excludeGoogleProtoFromArtifacts

// Apply some plugins to make type-safe extension accessors available in this script file.
plugins {
module
`compile-protobuf`
id("com.google.protobuf")
id("io.spine.descriptor-set-file")
id("io.spine.generated-sources")
`project-report`
ksp
}
Expand Down Expand Up @@ -87,3 +89,63 @@ configurations.all {
tasks {
excludeGoogleProtoFromArtifacts()
}


// For generating test fixtures. See `src/test/proto`.
protobuf {
configurations.excludeProtobufLite()

protoc {
artifact = Protobuf.compiler
}

generateProtoTasks.all().configureEach {
// Delete files generated in `com.google` packages because
// we add `protobuf(Protobuf.protoSrcLib)` dependency above.
doLast {
deleteComGoogle("java")
deleteComGoogle("kotlin")
}
}
}

/**
* Remove the code generated for Google Protobuf library types.
*
* The code for the `com.google` package was generated because we wanted
* to have descriptors for all the types, including those from Google Protobuf library.
* We want all the descriptors so that they are included into the resources used by
* the `io.spine.type.KnownTypes` class.
*
* Now, as we have the descriptors _and_ duplicating Java or Kotlin code, we delete it to avoid
* classes that duplicate those coming from Protobuf library JARs.
*
* @param language The programming language, either `"java"` or `"kotlin"`.
*/
fun GenerateProtoTask.deleteComGoogle(language: String) {
val comDirectory = generatedDir(language).resolve("com")
val googlePackage = comDirectory.resolve("google")

project.delete(googlePackage)

// If the `com` directory becomes empty, delete it too.
if (comDirectory.exists() && comDirectory.isDirectory && comDirectory.list()!!.isEmpty()) {
project.delete(comDirectory)
}
}

/**
* Obtains the path of the `generated` directory under the project root directory.
*/
private val Project.generatedDir
get() = projectDir.resolve("generated").toPath()

/**
* Obtains the `generated` directory for the source set of the task.
*
* If [language] is specified returns the subdirectory for this language.
*/
private fun GenerateProtoTask.generatedDir(language: String = ""): File {
val path = "${project.generatedDir}/${sourceSet.name}/$language"
return File(path)
}
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ import io.spine.gradle.report.pom.PomGenerator
buildscript {
standardSpineSdkRepositories()
doForceVersions(configurations)
dependencies {
classpath(io.spine.dependency.local.ToolBase.protobufSetupPlugins)
}
}

plugins {
Expand Down
53 changes: 0 additions & 53 deletions buildSrc/src/main/kotlin/compile-protobuf.gradle.kts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ package io.spine.dependency.local
@Suppress("ConstPropertyName", "unused")
object ToolBase {
const val group = Spine.toolsGroup
const val version = "2.0.0-SNAPSHOT.361"
const val version = "2.0.0-SNAPSHOT.363"

const val lib = "$group:tool-base:$version"
const val classicCodegen = "$group:classic-codegen:$version"
Expand All @@ -55,6 +55,8 @@ object ToolBase {
const val jvmTools = "$group:jvm-tools:$version"
const val jvmToolPlugins = "$group:jvm-tool-all-plugins:$version"

const val protobufSetupPlugins = "$group:protobuf-setup-plugins:$version"

object JavadocFilter {
const val group = ToolBase.group
const val version = "2.0.0-SNAPSHOT.75"
Expand Down
Loading
Loading