Search code examples
httpgradlebuildgradle-task

Gradle HTTP Plugin


I need to upload file with HTTP post in gradle build. I found HTTPPlugin which could make the deal. I made a simple build but it gives me error:

Caused by: groovy.lang.MissingPropertyException: Could not get unknown 
property 'HttpTask' for root project 'sample-app' of type 
org.gradle.api.Project.

build.gradle

plugins {
    id "io.github.http-builder-ng.http-plugin" version "0.1.1"
}

task notify(type:HttpTask){
    config {
        request.uri = 'http://something.com'
    }
    post {
        request.uri.path = '/notify'
        request.body = [event: 'activated']
        response.success {
            println 'The event notification was successful'
        }
    }
}

It seems gradle cannot find HTTPTask. Any idea what I'm missing?


Solution

  • The error "Could not get unknown property 'HttpTask' for root project" can be fixed by specifying the full qualified name of HttpTask type when declaring your task:

    task notify(type: io.github.httpbuilderng.http.HttpTask){
        config {
            request.uri = 'http://something.com'
        }
        post {
            request.uri.path = '/notify'
            request.body = [event: 'activated']
            response.success {
                println 'The event notification was successful'
            }
        }        
    }
    

    Best would be that this plugin declares an extension name "HttpTask" of type HttpTask.class so that we can directly use "HttpTask" without fully qualified name and without having to import this type in our script. This is how other plugins work (nebula ospakage plugin for example, with task "Rpm").

    Documentation of this plugin project should also be updated to provide a working example ( https://github.com/http-builder-ng/gradle-http-plugin )