How to implement Component tagging by modifying native commands

For Gradle:
def String gradleTasks = sh(script: “chmod a+x ${pipeProperties.projectDirectory}/gradlew && ‘${pipeProperties.projectDirectory}/gradlew’ --no-daemon tasks -b ${pipeProperties.projectDirectory}/build.gradle”, returnStdout: true).trim()

def String task = (gradleTasks ==~ /(?ms). Publishing tasks. /) ? ‘publish’ : ‘upload’

sh “’${pipeProperties.projectDirectory}/gradlew’ --no-daemon ${task} -b ${pipeProperties.projectDirectory}/build.gradle”

For Maven:
sh “’${mvnHome}/bin/mvn’ -f ${projectDirectory}/pom.xml deploy -Dmaven.test.skip=true -s ${projectDirectory}/settings.xml”

1. Is there any other way to implement Component tagging by modifying above native commands?

2. If multiple artifacts are getting uploaded using above commands then how does we do the component tagging?