Big Chungus
02/01/2022, 10:58 AMconvention-plugins
vs buildSrc
rekire
02/01/2022, 2:22 PMval javaConvention = project.convention.getPlugin(JavaPluginConvention::class.java)
however this failes since the project is not using javaEli Graber
02/01/2022, 10:43 PMapp
project that has an implementation dependency on a library
project that has an implementation dependency on an external artifact artifact
which lives in a private maven repo.
I have all of my repositories
defined in a convention plugin that all projects apply, but I don't want to keep the private maven repo info there. I've tried adding a repositories
block in library
to add that, but app
complains that it can't find artifact
. I assumed that only library
needs to know how to find it, but am I wrong, and anyone who depends on library
needs to as well?John Bellini
02/02/2022, 1:02 AMVlastimil Brecka
02/02/2022, 2:31 AM/Users/foo/.gradle/wrapper/dists/gradle-7.3.3-all/4295vidhdd9hd3gbjyw1xqxpo
What is that hash at the end? Can I calculate it myself?Eli Graber
02/02/2022, 6:35 AMbuild.gradle.kts
is this the correct way of setting that up?
in included build
abstract class MyTask : DefaultTask()
settings.gradle.kts
includeBuild("my-included-build") {
dependencySubstitution {
substitute(module("com.example:my-included-build")).using(project(":"))
}
}
app.gradle.kts
buildscript {
dependencies {
classpath("com.example:my-included-build")
}
}
If I'm using the included build in multiple projects, does it make sense to add that to the root project buildscript classpath?rekire
02/02/2022, 11:40 AMpluginManager.withPlugin("com.android.application") {
val app = project.the<ApplicationExtension>()
val buildTypes = app.buildTypes.map { it.name }
val sourceSets = app.sourceSets
My problem is now that I know the buildTypes debug and release, but how do I get the related sourcesets? In the code above sourceSets contains the name == "debug"
but how can I get now the resource directory from it? When I see it correctly then I can just add more directories, but I want to know the currently set onesCristian Garrido
02/02/2022, 2:59 PMA very common way for projects to be coupled is by using configuration injection. It may not be immediately apparent, but using key Gradle features like theWhyandallprojects
keywords automatically cause your projects to be coupled.subprojects
allprojects
and subprojects
keywords automatically cause your projects to be coupled. ? This is referred just for configuration phase? I appreciate very much an example of this, but just a better interpretation is great too 🙏Jan Duzinkiewicz
02/02/2022, 7:33 PMMichael Ondrejko
02/03/2022, 3:00 PMmvnPublication.pom.withXml { XmlProvider xml ->
def hasDependencies = !asNode().dependencies.isEmpty()
if (hasDependencies) {
asNode().dependencies.first().each {
def groupId = it.get("groupId").first().value().first()
def version = it.get("version").first().value().first()
if (groupId == 'testGroup' && version == 'changeVersion') {
it.get("version").first().value = newVersion
}
}
}
}
While this appropriately changes the published pom file, the Gradle module metadata (module.json) still retains the original version. This causes an inconsistency in the published Maven pom file and Gradle module metadata.
What is the proper way to make such a change that is reflected in both the published Maven pom file and Gradle module.json file?Ashwin Kachhara
02/03/2022, 5:47 PMEli Graber
02/03/2022, 10:41 PMThe request for this plugin could not be satisfied because the plugin is already on the classpath with an unknown version, so compatibility cannot be checked.
The use case is that I want to use the org.jetbrains.kotlin.plugin.parcelize
plugin, so I add an entry for it to my toml file and apply it using alias(libs.plugins.parcelize)
. However, I get the error above. I believe this is because it is added to the classpath by the Kotlin plugin (which I transitively add through a precompiled script plugin from an included build).
Is there any way to propagate the version information from the Kotlin plugin, so it could be inferred for the parcelize plugin?Colton Idle
02/06/2022, 6:50 AM./gradlew mymodule:test --tests "com.mymodule.testsuite" -Darg1="foo"
Retrieval that fails:
System.getProperty("arg1")
What am I doing wrong?Lars Ködderitzsch
02/07/2022, 8:06 AMval schemaZip by project.tasks.registering(Zip::class) {
group = "build"
description = "Erzeugt ein Schema-Artefakt"
from(processSchemaResources.map { it.processingOutDir })
into(archiveBaseName)
}
val `schema-artifact` by project.configurations.creating {
isTransitive = true
isCanBeConsumed = true
isCanBeResolved = false
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.DOCUMENTATION))
attribute(DocsType.DOCS_TYPE_ATTRIBUTE, project.objects.named("schema"))
attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling.EMBEDDED))
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named("schema-artifact"))
}
outgoing {
artifact(schemaZip)
}
}
val artifact = project.artifacts.add("schema-artifact", schemaZip)
The consumer plugin defines a new configuration "schema" which can be used to express dependencies on schema artifacts.
These are then unpacked into the consumer project and can be used to
* defined further schemas building on the dependencies, thus a combination of producer/consumer plugin
* consume schemas via various generator plugins
val schema by project.configurations.creating {
isTransitive = true
isCanBeConsumed = false
isCanBeResolved = true
attributes {
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named("schema-artifact"))
}
}
val schemaArtifactSpec = project.the<MyExtension>().schemaArtifact
val unpackSchemaDependencies by project.tasks.registering(Copy::class) {
group = "build setup"
description = "Extrahiert die Schema-Abhängigkeiten"
from(schema.map { project.zipTree(it) })
into(schemaArtifactSpec._dependenciesDir)
}
This works alright as long as schema dependencies in consumer projects are using the GAV notation.
In a multi project use case with project dependencies, however, the build seems to get the right idea that the consumer project wants the artifact produced by the producer project, but does not actually trigger the respective task ("schemaZip") to build it
Producer project (":a")
plugins {
id("my.schema-artifact")
}
Consumer project (":b")
plugins {
id("my.schema")
}
dependencies {
schema(project(":a"))
}
Build output:
> Task :b:unpackSchemaDependencies FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':b:unpackSchemaDependencies'.
> Cannot expand ZIP '<path-to-b>\build\distributions\my-a-1.0.0-SNAPSHOT.zip' as it does not exist.
What am I missing to get producer task in ":a" to trigger?Niv Sahar
02/07/2022, 5:50 PM./gradlew resolveAndLockAll --write-locks
the dependency is added to the gradle.lockfile under these configurations: io.opencensus:opencensus-impl-core:0.30.0=compileOnly,testCompileOnly
Then if i try to run ./gradlew clean build
I get the following error:
> Could not resolve all dependencies for configuration ':subproject-a:runtimeClasspath'.
> Resolved 'io.opencensus:opencensus-impl-core:0.30.0' which is not part of the dependency lock state
Also found out that if I run ./gradlew resolveAndLockAll --update-locks io.opencensus:opencensus-impl-core
it updates the lockfile with the right values: io.opencensus:opencensus-impl-core:0.30.0=compileOnly,default,runtimeClasspath,testCompileOnly,testRuntimeClasspath
but they get deleted every time I run resolveAndLock again. The problem isn't specific to this dependency, I've also seen it before in other projects and with other dependencies.
Any ideas? Thx!Zak Taccardi
02/08/2022, 12:48 AMbuildSrc
)? It’s failing for a specific plugin but causing all generation to fail :buildSrc:generatePrecompiledScriptPluginAccessors
Zak Taccardi
02/08/2022, 2:40 AMid("com.malinskiy.marathon")
has to download the marathon CLI binary, so it’s done once for the root project and then that binary can be shared across all subprojectsZak Taccardi
02/08/2022, 10:06 PMVersionCatalogsExtension
due to Extension of type 'VersionCatalogsExtension' does not exist
val versionCatalog = extensions.getByType<VersionCatalogsExtension>()
Is there a specific plugin I need to apply to enable this?Big Chungus
02/09/2022, 12:29 PMZak Taccardi
02/10/2022, 12:07 AMid("com.malinskiy.marathon")
given how my project is setup.
* What went wrong:
An exception occurred applying plugin request [id: 'zak.conventions.library.android']
> Failed to apply plugin 'zak.marathon.plugin'.
> Plugin with id 'com.malinskiy.marathon' not found.
A subproject in my main build applies zak.conventions.library.android
(defined in buildSrc
) - which itself applies:
// zak.conventions.library.android (in buildSrc)
plugins {
// this plugin request fails
id("com.malinskiy.marathon") // note - this plugin is not defined in `plugins { }` in `buildSrc`
}
> Configure project :buildSrc
requesting plugin: [id: 'org.gradle.kotlin.kotlin-dsl', version: '2.1.7']
requesting plugin: [id: 'org.gradle.java-gradle-plugin']
requesting plugin: [id: 'org.jetbrains.kotlin.jvm', version: '1.5.31']
> Configure project :
requesting plugin: [id: 'xxxxxxx']
> Configure project :main-build-subproject
requesting plugin: [id: 'zak.conventions.library.android']
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/user1/zak/main-build-subproject/build.gradle.kts' line: 6
* What went wrong:
An exception occurred applying plugin request [id: 'zak.conventions.library.android']
> Failed to apply plugin 'zak.marathon.plugin'.
> Plugin with id 'com.malinskiy.marathon' not found.
// ..
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/user1/zak/main-build-subproject/build.gradle.kts' line: 6
* What went wrong:
An exception occurred applying plugin request [id: 'zak.conventions.library.android']
> Failed to apply plugin 'zak.marathon.plugin'.
> Plugin with id 'com.malinskiy.marathon' not found.
What am I doing wrong?tony
02/10/2022, 12:48 AM> Task :compileKotlin
'compileJava' task (current target is 11) and 'compileKotlin' task (current target is 1.8) jvm target compatibility should be set to the same Java version.
I feel like this should cover it
val javaLanguageVersion = JavaLanguageVersion.of(11)
java {
toolchain {
languageVersion.set(javaLanguageVersion)
}
}
kotlin {
jvmToolchain {
(this as JavaToolchainSpec).languageVersion.set(javaLanguageVersion)
}
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "11"
}
}
I mean, it should more than cover it. And yetZak Taccardi
02/10/2022, 7:33 PMimplementation(..)
for the android and java plugins?
I’d like to do something similar myself as the version of AGP I’m on does not support implementation(provider)
yetGilles Robert
02/11/2022, 4:52 AMcody mikol
02/11/2022, 3:41 PMNikolay
02/11/2022, 6:42 PMplugins {
id("jacoco-report-aggregation")
alias(libs.plugins.ktlint)
}
repositories {
mavenCentral()
}
allprojects {
repositories {
mavenCentral()
gradlePluginPortal()
}
}
reporting {
reports {
val testAggregateTestReport by creating(AggregateTestReport::class) {
testType.set(TestSuiteType.UNIT_TEST)
}
}
}
And I get the following error:
Cannot create a AggregateTestReport because this type is not known to this container. Known types are: JacocoCoverageReport
> org.gradle.api.internal.NoFactoryRegisteredForTypeException (no error message)
Any idea why this is not working?Ramesh Vangala
02/15/2022, 7:15 AMplugins {
id 'com.reputation.r4e.java-conventions'
id 'org.springframework.boot'
id 'io.spring.dependency-management'
}
springBoot {
mainClass = ''
buildInfo{
properties {
additional = [
'build.commitid' : "" + System.getenv("git.commit.id"),
'build.buildNumber': "" + System.getenv("BUILD_NUMBER"),
'build.buildurl' : "" + System.getenv("jenkins.url")
]
}
}
}
bootJar {
archiveClassifier = 'boot'
enabled = false
}
sourceSets {
main {
java {
srcDirs = ['src/main/java']
}
resources {
srcDirs = ['src/resources']
}
}
test {
java {
srcDirs = ['src/test/java']
}
resources {
srcDirs = ['src/test/config', 'src/test/resources']
}
}
}
processResources {
filesMatching('**/*.factories'){
expand(gradle.properties)
}
}
processTestResources {
filesMatching('**/*.factories'){
expand(gradle.properties)
}
}
jar {
archiveClassifier = ''
into('./') {
from('src/main/resources') {
include '*.*'
}
from('src/main/config') {
include '**/*.*'
}
}
}
dependencies {
implementation projects.r4eCore
implementation projects.r4eLogging
implementation projects.r4eInstrumentation
implementation projects.r4eThrift
implementation projects.r4eUtils
implementation projects.r4eDaoThrift
implementation projects.r4eAggregatorThrift
implementation(libs.janino.janino)
implementation(libs.logback.logback.classic)
implementation(libs.logback.logback.core)
implementation(libs.logstash.logback.encoder)
implementation(libs.guava.guava)
implementation(libs.spring.boot.starter.actuator.autoconfigure)
implementation(libs.spring.boot.starter.mongodb)
implementation(libs.spring.boot.starter.data.redis)
implementation(libs.spring.boot.starter.webflux)
implementation(libs.spring.boot.starter.amqp)
implementation(libs.apache.commons.math3)
implementation(libs.slf4j.slf4j.api)
implementation(libs.apache.commons.lang3)
implementation(libs.apache.commons.beanutils)
implementation(libs.apache.commons.collections4)
implementation(libs.apache.commons.csv)
implementation(libs.github.classgraph.classgraph)
implementation(libs.javax.validation.api)
implementation(libs.micrometer.micrometer.registry.prometheus)
implementation(libs.apache.commons.compress)
implementation(libs.apache.thrift.libthrift)
implementation(libs.gson.gson)
implementation(<http://libs.apache.commons.io|libs.apache.commons.io>)
testImplementation(libs.spring.boot.test)
testImplementation(libs.spring.boot.starter.test)
testImplementation(libs.hibernate.hibernate.validator)
testImplementation(libs.junit5.vintage.engine)
}
description = 'r4e-common'
java {
withSourcesJar()
}
test {
useJUnit()
useJUnitPlatform()
}
Please help me regarding this. Concept: Spring internationalisation/MessagesSourceChris
02/15/2022, 2:53 PMDeepthi Kodatham
02/16/2022, 5:20 PMZak Taccardi
02/16/2022, 11:30 PMbuildscript { }
and the rest of the build.gradle.kts
file?
buildscript {
// this fails with class not found exception
val myClass = SomeClass()
}
val myClass = SomeClass()
class SomeClass { }
Zak Taccardi
02/17/2022, 1:47 AMRegularFile
in a settings.gradle.kts
script? I don’t see access to layout
(which makes sense)