在Maven原型期间发出HTTP请求: [英] Making HTTP requests during maven archetype:generate

查看:177
本文介绍了在Maven原型期间发出HTTP请求:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个原型,用于在公司内部创建标准化项目.生成的实际项目文件很好,我现在想将原型与设置基础结构(例如Stash存储库和Jenkins作业)的过程集成在一起.

I'm building an archetype for creating standardised projects within the company. The actual project files generated are fine, I'd now like to integrate the archetype with the process of setting up infrastructure, such as Stash repositories and Jenkins jobs.

例如,简单地说,我希望maven archetype:generate进程包括对http://stash.example.com/rest/api/1.0/projects/LABS/repos/{artifactId}的HTTP REST POST,以便创建GIT存储库.

For example, simplistically I'd like the maven archetype:generate process to include an HTTP REST POST to http://stash.example.com/rest/api/1.0/projects/LABS/repos/{artifactId} in order to create a GIT repo.

与詹金斯(Jenkins)的建造工作类似.如果在创建Maven项目之前,可以对Stash/Jenkins进行一些测试以防止名称冲突,那就太好了.

Likewise something similar for Jenkins build jobs. I would be nice if, prior to creating the maven project, some tests could be done to Stash/Jenkins to prevent name collisions.

我想解决此问题的方法是将一些Maven插件绑定到某些构建阶段.

I imagine the solution to this is to bind some maven plugins to some build phases.

我一直无法找到任何现有的插件,也找不到原型生成过程中做类似事情的人的例子(没有Groovy锤子).

I've been unable to find any existing plugins, or examples of people doing similar during an archetype generation (without the Groovy hammer).

  1. 是否有任何现有的Maven插件可在构建期间协助发出HTTP/REST请求?
  2. 是否有任何现有的Maven插件可帮助访问Stash或Jenkins API?
  3. 哪个Maven阶段是比较根据远程系统检查选定名称/标识的合适候选者,哪个阶段是实际创建远程资源的合适候选者?

有人尝试过这种方法吗?如果可以,那么如何解决?

Has anyone tried this sort of thing, and if so how did it work out?

我看到一些相关问题

  • Making HTTP post request (with an input type="file") from within Maven, using command line parameters if possible
  • maven plugin to call or invoke a rest web service

和一些潜在的插件

推荐答案

有两种方法可以执行此操作.我们以前使用的两种方法是使用

There are couple of of ways you can do this. Two ways we did this previously were using:

1.使用groovy-gmaven插件和其中的RESTClient

我们的代码粘贴到这里有点复杂,但是我们做了一些非常类似的事情:

Our code is a bit complicated to paste here, but we did some thing very similar to this:

使用Maven进行Groovy Rest调用

2. Antcontrib的loadresource:

示例:

<loadresource property="build_start_date">
   <url url="${JOB_URL}/lastSuccessfulBuild/api/xml?xpath=/*/id/text()"/>
</loadresource>

这将连接到hudson rest api,并获取存储在属性 build_start_date 中的上次构建日期.

This connects to a hudson rest api and get's me the last build date which is stored in the property build_start_date.

这篇关于在Maven原型期间发出HTTP请求:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆