Maven-publish component based on applied plugin

Is there an option to generalize maven-publish plugin, in order to dynamically choose which component to publish (java or web) based on applied plugin (java or war)? Currently I have my publishing repositories configured in init.gradle and then all my projects need to have specified which component to use separatelly.

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }
}

I would like to have all publish related configuration in init.gradle even which component to publish for all projects.