Thursday, July 16, 2015

How to exclude a file when publishing an artifact to Maven repository in Gradle

To exclude a `logback.xml` file when publishing an artifact to Maven repository in Gradle,

you can use the following configuration:

ext {
    artifactId = project.name
    artifactVersion = project.version
}

jar {
    baseName = artifactId
    version = artifactVersion
}

task commonJar(type: Jar) {
    baseName "test-common"
    from sourceSets.main.output
    exclude 'logback.xml'
}

publishing {
    repositories {
        maven {
            credentials {
                username "admin"
                password "1234"
            }
            url "http://repo.test.com:8080/repository/internal"
        }
    }

    publications {
        maven(MavenPublication) {
            groupId 'com.test'
            artifactId artifactId
            version artifactVersion

            artifact commonJar
        }
    }
}

Reference:
https://docs.gradle.org/current/userguide/publishing_maven.html

No comments:

Post a Comment