https://kotlinlang.org logo
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
benchmarks
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
confetti
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
lincheck
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by
Title
u

ursus

07/21/2019, 6:31 PM
Hi, im trying to run tests before
assembleRelease
Usually I do it in app build.gradle via
afterEvaluate {
    assembleRelease.dependsOn test
}
However this doesnt work for my multimodule app, It seems that code only runs tests in :app I could add that block to every module's build file but that is error prone I tried
allprojects {
   afterEvaluate {
       assembleRelease.dependsOn test
   }
}
* What went wrong:
A problem occurred configuring root project 'icewarp-teamchat-android'.
> Could not get unknown property 'assembleRelease' for root project 'abc' of type org.gradle.api.Project.
d

Dominaezzz

07/21/2019, 6:32 PM
Try
subprojects
instead of
allprojects
.
u

ursus

07/21/2019, 6:57 PM
subprojects {
    afterEvaluate {
        println tasks
    }
}
same as allprojects, I dont see neiter
assembleRelease
not `test`˛in the list
@Dominaezzz
d

Dominaezzz

07/21/2019, 6:58 PM
Then where are they?
afterEvaluate {
    assembleRelease.dependsOn(':app:test')
}
u

ursus

07/21/2019, 7:07 PM
I dont know, but they exist I can run them manually, I think some evaluation timing is the issue
@Dominaezzz that wont work, I cannot see assembleRelease, and even if I could, youd depend on the app:test only
d

Dominaezzz

07/21/2019, 7:08 PM
Hmm, not sure why this is happening.
u

ursus

07/21/2019, 7:09 PM
I feel this is stupid anyways, there must be a hook into global assembleRelease to run global test task, not per module
allprojects {

    afterEvaluate {
        // Run each module's test task after each module's assembleRelease
        tasks.whenTaskAdded { task ->
            if (task.name == "assembleRelease") {
                task.dependsOn "test"
            }
        }
this works
d

Dominaezzz

07/21/2019, 7:18 PM
Wow, that's some seriously lazy task config.
Glad there's a solution still.
u

ursus

07/21/2019, 7:25 PM
I was surprised this not being easily googlable, but it seems that CIs run simply a command gradlew test, they dont care about internal gradle tasks etc
g

gildor

07/22/2019, 1:59 AM
It also quite error-prone, because if you have different flavors it will not run test One problem is that module just don’t have assembleRelease, it has just assemble, for example pure JVM module, it will do nothing and test will not be run
u

ursus

07/22/2019, 5:14 AM
you can bake that flavor support in the task name string, but yea .. is there a better way? this feels needlessly brittle
g

gildor

07/22/2019, 5:54 AM
I would use proper task for this
that does exactly what you want
instead adding it to assembleRelease
u

ursus

07/22/2019, 6:10 AM
what do you mean proper task? @gildor how else do you build your releases other than assembleRelease?
g

gildor

07/22/2019, 6:15 AM
I release using own publishing task, and this task depends on
check
task
Gradle provides a few “lifecycle” tasks, that do nothing but just hooks for other tasks: build, assemble, check
and check is a hook that should be used for all test tasks (it’s already true for test tasks)
I don’t want to say that there is easy way, unfortunately, because of more complicated project structure for Android, check and test do not exactly what you usually want, but I think it’s still good rule: configure each module in a way that attach different behaviors to lifecycle, so before publish you just run check that runs all tasks with tests
again, it’s not something ready to use, but I think it’s better to be explicit instead implicit convention with assembleRelease task
u

ursus

07/22/2019, 6:42 AM
I might be missing something, how do you actually build release if not with assemble<X>Release? regardless if this is triggered by your custom task or not, something still needs to call that
g

gildor

07/22/2019, 6:44 AM
build it with a task that runs your tests and runs assembleRelease
u

ursus

07/22/2019, 6:45 AM
well thats my point, that you need to hardcode or somehow parametrize the assembleXRelease in it, therefore you have the same brittleness I think, as that x.dependsOn test
from what I understand you just created customTask.dependsOn assembleRelease.dependsOn test
g

gildor

07/22/2019, 6:46 AM
no
you implicitly add those dependencies
my point that every module or every type of module knows what should be checked
and you explitly run this check/test task
u

ursus

07/22/2019, 6:48 AM
so root should whitelist all modules tests tasks?
g

gildor

07/22/2019, 6:48 AM
no, every module should run own test tasks
u

ursus

07/22/2019, 6:49 AM
well, who tells them to run them?
root test task?
g

gildor

07/22/2019, 6:49 AM
no
u

ursus

07/22/2019, 6:50 AM
then I dont understand
g

gildor

07/22/2019, 6:50 AM
when you run
check
it will execute task with this name in all modules
not root, but every module has own
u

ursus

07/22/2019, 6:51 AM
yes, prefixless check/test
g

gildor

07/22/2019, 6:51 AM
this is how Gradle task work
yes
u

ursus

07/22/2019, 6:51 AM
thats why I meant by root
g

gildor

07/22/2019, 6:51 AM
it’s bad name for it
it’s not root, root module also may have
test
task
u

ursus

07/22/2019, 6:51 AM
okay top level test
g

gildor

07/22/2019, 6:52 AM
but when you run task without full path, Gradle just tries to run this task in all modules
no
you probbably don’t understand how gradle task execution works
./gradlew test - means please, run task with name “test” in all modules, where this task exist. UPD: And do nothing for modules where this task doesn’t exist
./gradflew :module:test - run task with name “test” in module with name “module”
u

ursus

07/22/2019, 6:53 AM
well, gradle is a mistery most of the time but that I know 😀
g

gildor

07/22/2019, 6:53 AM
./gradlew :test - means please, run task with name “test” in root module
u

ursus

07/22/2019, 6:54 AM
okay but, how can I have test task fail the release task?
I thought thats accomplished by assembleRelease.dependsOn test
g

gildor

07/22/2019, 6:54 AM
yes, it will
every task in graph in case of fail will fail the build
u

ursus

07/22/2019, 6:55 AM
okay but in terms of how woukd the task look
isnt it chain of x.dependsOn y?
g

gildor

07/22/2019, 6:56 AM
does it make sense which task is fail and order of them?
u

ursus

07/22/2019, 6:56 AM
not sure what you mean, Id fail the task on first error
g

gildor

07/22/2019, 6:57 AM
yes, this what will happen
again, I think, that assembleRelease.dependsOn test is not right approach
assemble is just assemble, it shouldn’t test anything, this is the point of this task
u

ursus

07/22/2019, 6:57 AM
right but what is the gradle syntax? I thought it was assembleRelease dependsOn test
g

gildor

07/22/2019, 6:57 AM
assemble on Jvm module doesn’t run tests
u

ursus

07/22/2019, 6:58 AM
Im not arguing, with gradle im mostly bashing it until it works
g

gildor

07/22/2019, 6:58 AM
it just assemble project, there is
build
lifecycle task which assemble and check the project
Yes, syntax is correct
but Android modules don’t have
test
task by default, at least as I remember, thehy have only testDebugUnit
u

ursus

07/22/2019, 6:59 AM
Im confused, if you say its correct then whats wrong
you say assembleReleade.dependsOn test breaks the lifecycle separation thing
g

gildor

07/22/2019, 6:59 AM
I;’m saying that it’s wrong approach to add test to dependencies of assemble
not a problem of syntax
u

ursus

07/22/2019, 7:00 AM
then how should I have test be prerequisite of assembleRelease?
g

gildor

07/22/2019, 7:01 AM
for example ruse
build
lifecycle task that builds only assembleRelease and run tests
This is was my original argument
That no need to add dependencies to assembleRelease, this task does exactly what it should do
at least this is how I see it
u

ursus

07/22/2019, 7:01 AM
build
already does that?
doesnt build build every type and flavor etc?
g

gildor

07/22/2019, 7:02 AM
nope, but you can implement it
doesnt build build every type and flavor etc?
yes, most probably this is default behavior
you always can have buildRelease
u

ursus

07/22/2019, 7:02 AM
Okay, but via what syntax if not the dependsOn?
g

gildor

07/22/2019, 7:02 AM
or something like this
I said nothing about syntax
I’m telling about semantics
I also think that it’s inccorrect how Android plugin configures graph and add lint as dependency to release task
u

ursus

07/22/2019, 7:03 AM
well
task buildRelease {
   assembleRelease.dependsOn test
}
g

gildor

07/22/2019, 7:03 AM
nope
u

ursus

07/22/2019, 7:04 AM
is where we started with
g

gildor

07/22/2019, 7:04 AM
task buildRelease {
   dependsOn assembleRelease test
}
u

ursus

07/22/2019, 7:04 AM
yea didnt know you could do that, thanks
g

gildor

07/22/2019, 7:04 AM
just a task that depends on 2 other tasks
u

ursus

07/22/2019, 7:08 AM
btw will that work the way you wrote it? Since assembleRelease becomes available later in time etc.
g

gildor

07/22/2019, 7:14 AM
what do you mean? are you applying it in allprojects?
assembleRelease make sense only for application module, so it should be configured there
you can use afterEvaluate of course
I use custom plugins, but also it’s possible to do using plugin application hooks. plugin.withType(LibraryPlugin) etc
u

ursus

07/22/2019, 7:24 AM
Well I thought that buildDelease task should be in project level build.gradle, since its top level or whatever the naming
g

gildor

07/22/2019, 7:25 AM
It’s possible to do of course
we use custom gradle plugins to share any config, so it’s always explicit
u

ursus

07/22/2019, 6:46 PM
Hi @gildor, so I tried it
task buildRelease() {
    dependsOn "assembleRelease", "test"
    group "build"
    description "Build release apk for deployment and runs tests"
}
If I put that in app/build.gradle then, it builds release however only runs :app:test, not library modules So, I tried putting it in project build.gradle and I get
* What went wrong:
Could not determine the dependencies of task ':buildRelease'.
> Task with path 'test' not found in root project 'icewarp-teamchat-android'.
which I dont understand, I see it there
g

gildor

07/23/2019, 1:32 AM
Do you really have test task on your root project? Does it Android or Java module itself?
u

ursus

07/23/2019, 3:42 AM
Not sure what you mean; its an android project; its generated by someone automatically, all project seem to have it for me
g

gildor

07/23/2019, 3:47 AM
but do you apply android plugin to this module? looks that it’s your root project
u

ursus

07/23/2019, 4:53 AM
no its the root, has no plugins
g

gildor

07/23/2019, 4:55 AM
so, if so you don’t have test there
u

ursus

07/23/2019, 5:28 AM
yes I do, i posted the screenshot
g

gildor

07/23/2019, 5:29 AM
This is just idea representation
run
:test
u

ursus

07/23/2019, 2:40 PM
* What went wrong:
Task 'test' not found in root project 'icewarp-teamchat-android'.
so where should I put the buildRelease so it works with prefixless
test
? I would not expect the task physical location to matter if it references :module or prefixless explicitly