Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to publish an XML file to Maven repo from Gradle

I have a static xml file that I want to publish to a Maven repository (my local Maven repo for now) from Gradle using the maven-publish plugin.

build.gradle looks like this:

apply plugin: 'maven-publish'

group 'com.example.gradletest'
version '1.0-SNAPSHOT'

publishing {
    publications {
        beta(MavenPublication) {
            artifactId 'feature-file'
            artifact 'src/main/resources/features.xml'
        }
    }
}

This works, but I would like to add a classifier too, where should I define that? https://docs.gradle.org/current/userguide/publishing_maven.html says in section 68.2.2 that it should be possible to do:

publishing {
    publications {
        beta(MavenPublication) {
            artifactId 'feature-file'
            artifact ('src/main/resources/features.xml') {
                classifier 'features'
            }
        }
    }
}

but then I get this error:

A problem occurred configuring root project 'testapplication'.

Exception thrown while executing model rule: org.gradle.api.publish.plugins.PublishingPlugin$Rules#publishing(org.gradle.api.plugins.ExtensionContainer) No signature of method: java.io.File.call() is applicable for argument types: (build_101arjzoe908rdkh5aikrn6bt$_run_closure5_closure16_closure19_closure20) values: [build_101arjzoe908rdkh5aikrn6bt$_run_closure5_closure16_closure19_closure20@2aa7399c] Possible solutions: wait(), any(), wait(long), each(groovy.lang.Closure), any(groovy.lang.Closure), list()

Using the below solution will correctly add the classifier, but will also change the packaging in the pom.xml from <packaging>xml</packaging> to <packaging>pom</packaging>. I don't want that.

publishing {
    publications {
        beta(MavenPublication) {
            artifactId 'feature-file'
            artifact source: 'src/main/resources/features.xml', classifier: 'features'
        }
    }
}
like image 778
npeder Avatar asked Nov 01 '25 05:11

npeder


2 Answers

Use the map syntax as specified here.

publishing {
    publications {
        beta(MavenPublication) {
            artifactId 'feature-file'
            artifact source: 'src/main/resources/features.xml', classifier: 'features'
        }
    }
}
like image 63
advayDev1 Avatar answered Nov 04 '25 05:11

advayDev1


Adding pom { packaging 'xml' }

works for me (gradle 3.2.1)

publishing { publications { beta(MavenPublication) { artifactId 'feature-file' artifact source: 'src/main/resources/features.xml', classifier: 'features' pom { packaging 'xml' } } } }

like image 24
Alexey Barsov Avatar answered Nov 04 '25 05:11

Alexey Barsov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!