Gradle multi project build query - exclude compilation of subprojects based on env

I’m using gradle-7.2 with multi-project build feature, where my main service consists of multiple sub modules. I’ve defined structure like this:

MYSERVICE
----abc-api
    |
    ---build.gradle 
----abc-impl
    |
    ---build.gradle 
----xyz-api
    |
    ---build.gradle 
----xyz-impl
    |
    ---build.gradle
lib
 <<all libs used by service extracted from subprojects compile/runtime classpath and placed here>>
bin
<<service startups scripts reside here>>
conf
<<service configuration files reside here>>
settings.gradle 
build.gradle

settings.gradle

rootProject.name = 'MYSERVICE'
include 'abc-api'
include 'xyz-api'
include 'abc-impl'
include 'xyz-impl'

build.gradle

apply plugin: 'java'
apply plugin: 'application'

subprojects {
    task allDeps(type: DependencyReportTask) {}
}

configurations {
    runtimeClasspath.transitive = false
}

dependencies {
        
        /**
        * some additional runtime libs used by those subprojects
        */
        
        /** deps needed for spring framework **/
        runtimeOnly "com.xyz.comp:aopalliance:1.0"
        runtimeOnly "com.xyz.comp:spring-aop:5.3.22"
        runtimeOnly "com.xyz.comp:spring-tx:5.3.22"
        runtimeOnly "com.xyz.comp:spring-expression:5.3.22"
        runtimeOnly "com.xyz.comp:osgi.core:8.0.0"
        

}

task getFlatDependencies(type: Copy) {
    from {
        subprojects.findAll { it.getSubprojects().isEmpty() }
                    .collect { it.configurations.runtimeClasspath + it.configurations.compileClasspath }
                    
    }
    into 'lib'
    
    from configurations.runtimeClasspath
    into 'lib'
    
    exclude "sourceanalyzer-1.0.jar"
}

build.dependsOn(getFlatDependencies)

All this works fine, but i want to do one additional improvement here. When i run gradle build at service level, its compiling all the sub projects and preparing lib. I want to avoid this compilation stuff in case of QA environment (as i get jars from artifactory for QA env) but needed for local environment setup.

How can i achieve this?