GithubHelp home page GithubHelp logo

http-builder-ng / gradle-http-plugin Goto Github PK

View Code? Open in Web Editor NEW
31.0 3.0 8.0 546 KB

Gradle plugin providing support for using HttpBuilder-NG to make HTTP requests as Gradle Tasks.

Home Page: https://http-builder-ng.github.io/gradle-http-plugin/

License: Apache License 2.0

Groovy 61.59% HTML 7.93% CSS 30.48%
gradle-plugin groovy java httpbuilder-ng http dormant

gradle-http-plugin's Introduction

Gradle HTTP Plugin

Build Status Coverage Status

Dormant - The HttpBuilder-NG project is going dormant. Neither of us use the project any longer nor do we have the extra time to properly maintain it. Please feel free to fork it and move it forward, or contact us (with an issue) to discuss options for taking over the project.

Quick Links

Introduction

A Gradle plugin providing the ability to define tasks to make HTTP requests using the HttpBuilder-NG client library. The resulting tasks have a clean DSL and will look something like the following:

Groovy

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'
        }
    }
}

Kotlin

tasks {
    val notify by registering(HttpTask::class) {
        config {
            it.request.setUri = "http://something.com"
        }
        post {
            it.request.uri.setPath("/notify")
        }
        response.success { fromServer, body ->
            println("The event notification was successful")
        }
    }
}

Installing

The plugin is available through the Gradle Plugin Repository and may be applied to your Gradle build with one of the following:

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

or

buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "gradle.plugin.io.github.http-builder-ng:http-plugin:0.1.1"
  }
}

apply plugin: "io.github.http-builder-ng.http-plugin"

Building

The project is build with Gradle using the following command:

./gradlew clean build

License

The Gradle HTTP Plugin is licensed under the Apache 2 open source license.

Copyright 2017 HttpBuilder-NG Project

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the License for the specific language governing permissions and limitations under
the License.

gradle-http-plugin's People

Contributors

cjstehno avatar eskatos avatar fviolette avatar jmeekhof avatar sciencesakura avatar toxicbakery avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gradle-http-plugin's Issues

Support client selection at configuration time

I know there is a way to add dependencies to a plugin when it is applied. It would be nice to be able to only download the HttpBuilder-NG client library that is selected rather than having all three present in all use cases.

Alternately, I guess I could have three separate Gradle plugins, one for each client, but I'd rather not.

If you use this plugin and care about having an isolated client distribution, comment on this issue or give it a thumbs up.

Error on input/output annotations

Using Gradle 7, they've changed the rules on input/output annotations such that they now only work on getter/setters which results in half a dozen errors like this when using the plugin:

Some problems were found with the configuration of task ':api:notifyVersion' (type 'HttpTask').
  - Type 'io.github.httpbuilderng.http.HttpTask' method 'config()' should not be annotated with: @Input.
    
    Reason: Input/Output annotations are ignored if they are placed on something else than a getter.
    
    Possible solutions:
      1. Remove the annotations.
      2. Rename the method.
    
    Please refer to https://docs.gradle.org/7.0.2/userguide/validation_problems.html#ignored_annotations_on_method for more details about this problem.

The list of impacted methods I'm seeing is

config
delete
deleteAsync
get
getAsync

Does not work inside of a doLast block

I wrote a dead simple post request and tested that it works.
Only issue was that it ran every time I synced my project. So I put it inside of a doLast block, and now I get this error message:

A configuration closure or consumer must be provided either globally or by the task configuration

task exportTranslations(group: "crowdin", type: HttpTask) {
    doLast {
        config {
            request.uri = "https://api.crowdin.com/api/project/$PROJECT_IDENTIFIER/export?key=$API_KEY"
        }
        post {
            response.success {
                println("Export successful")
            }
        }
    }
}

Could not get unknown property 'HttpTask'

trying to add HttpTask to ftc_app android app:
https://github.com/ftctechnh/ftc_app
in the root build.gradle I changed it to:

buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        classpath "gradle.plugin.io.github.http-builder-ng:http-plugin:0.1.1"
    }
}

in build.common.gradle, I changed the top to of the file to the following:

import java.util.regex.Pattern

apply plugin: 'com.android.application'
apply plugin: "io.github.http-builder-ng.http-plugin"

http {
    library = 'apache'
    config {
        request.uri = 'http://localhost:1234'
    }
}

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'
        }
    }
}

when I sync the project, triggering a gradle build I receive the following error:

Could not get unknown property 'HttpTask' for project ':TeamCode' of type org.gradle.api.Project.

Unable to Build

I've encountered a similar issue and am including the output of a run with stacktrace and debug flags enabled in hopes that it's helpful:

output.txt

Here is the task I attempted to configure:

task refreshPlugins(type:HttpTask) {
    config {
        request.uri = 'https://artifactory.test.net/artifactory'
    }
    post {
        request.uri.path = '/api/plugins/reload'
        response.success {
            lifecycle.info 'Plugins reloaded on test instance.'
        }
    }
}

and my plugins block:

plugins {
  id 'groovy'
  id 'org.hidetake.ssh' version '2.9.0'
  id 'io.github.http-builder-ng.http-plugin' version '0.1.1'
}

Can't use in build

I have included many plugins in my build without error.

However with you plugin what ever I do the build doesn't recognise the HttpTask class. I may be doing something wrong but I have spent at least 30 minutes trying to get this to work. Normally with a plugin I don't need to spend more then 1 minute, given I have 18 years experience coding. I would suggest either your plugin doesn't work or you are doing something non-standard or your instructions are not clear. Certainly all other plugins I've used are much easier to start using without any issues.

Maintainers wanted

If you like using this plugin and want to help keep it around, please feel free to pitch in and fix issues or add features.

I will be happy to review and merge valid pull requests.

Unable to configure using kotlin

I'm attempting to use this plugin using the kotlin DSL. Has anyone had any luck?


http {
    config {
        request.uri.set("${gHostUriType}://${gHost}:${gRestPort}")
    }
}

yields


  Line 33:         request.uri.set("${gHostUriType}://${gHost}:${gRestPort}")
                   ^ Unresolved reference: request

Request.body sending null

I am making Http Post call using the plugin io.github.http-builder-ng.http-plugin. Below is my build.gradle

plugins {
     id "io.github.http-builder-ng.http-plugin" version "0.1.1"
}
task makeRESTCall (type: io.github.httpbuilderng.http.HttpTask) {
    onlyIf {
        !dependencyList.empty // this list is set by other task 
    }
    doFirst {
        println dependencyList // printing fine
    }
    config {
        request.uri = 'http://localhost:8080'
        request.contentType = 'application/json'
        request.accept = '*'
        request.uri.path = '/api/v1/validate'

    }
    post {
        request.body = dependencyList
        response.success {
            println "Success"
        }
    }
}

This is my dependencyList parameter that am sending in request.body

[

{
    "groupId":"org.hibernate",
    "artifactId":"hibernate-validator",
    "version":"5.3.6.Final"
}, 
{
    "groupId":"org.projectlombok",
    "artifactId":"lombok",
    "version":"1.16.22"
}, 
{
    "groupId":"io.springfox",
    "artifactId":"springfox-swagger-ui",
    "version":"2.8.0"
}
]

My java code in my backend API (written in Spring Boot) just prints in this format

incomingLists.stream().forEach(
            obj -> System.out.println(obj.getGroupId()+" **** "+obj.getArtifactId()+" **** "+obj.getVersion())
        );

When i hit this API from my postman, the response is correct- see below print from the code

org.hibernate **** hibernate-validator **** 5.3.6.Final
org.projectlombok **** lombok **** 1.16.22

whereas when i hit the same API from my gradle task, my java code prints it this way.. because the inner objects are null

null **** null **** null
null **** null **** null

Am not sure if am missing anything

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.