TeamCity插件开发maven失败

Posted

技术标签:

【中文标题】TeamCity插件开发maven失败【英文标题】:TeamCity plugin development maven failure 【发布时间】:2017-03-14 19:37:25 【问题描述】:

我正在关注https://confluence.jetbrains.com/display/TCD10/Getting+Started+with+Plugin+Development的插件开发教程

在第 2 步运行命令时:

mvn archetype:generate -DarchetypeRepository=http://download.jetbrains.com/teamcity-repository -DarchetypeArtifactId=teamcity-server-plugin -DarchetypeGroupId=org.jetbrains.teamcity.archetypes -DarchetypeVersion=RELEASE

我收到以下错误:

[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> maven-archetype-plugin:3.0.0:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO] 
[INFO] <<< maven-archetype-plugin:3.0.0:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO] 
[INFO] --- maven-archetype-plugin:3.0.0:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[WARNING] Archetype not found in any catalog. Falling back to central repository (http://repo.maven.apache.org/maven2).
[WARNING] Use -DarchetypeRepository=<your repository> if archetype's repository is elsewhere.
Downloading: http://repo.maven.apache.org/maven2/org/jetbrains/teamcity/archetypes/teamcity-server-plugin/maven-metadata.xml
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.638 s
[INFO] Finished at: 2017-03-14T11:24:41-06:00
[INFO] Final Memory: 14M/185M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.0.0:generate (default-cli) on project standalone-pom: The desired archetype does not exist (org.jetbrains.teamcity.archetypes:teamcity-server-plugin:RELEASE) -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

关于如何让它发挥作用的任何想法?

【问题讨论】:

【参考方案1】:

Maven Archetype 3.0.0 移除了archetypeRepository 参数,见https://issues.apache.org/jira/browse/ARCHETYPE-439

因此,您必须将远程原型存储库添加到您的 settings.xml 中。转到您的 [users]/.m2 文件夹,像这样创建/编辑 settings.xml:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                          https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <profiles>
    <profile>
      <id>teamcity</id>
      <repositories>
        <repository>
          <id>teamcity-repository</id>
          <name>Teamcity Repository</name>
          <url>http://download.jetbrains.com/teamcity-repository</url>
          <layout>default</layout>
        </repository>
      </repositories>          
    </profile>
  </profiles>
</settings>

然后在你的命令行执行maven

 mvn archetype:generate -P teamcity -DarchetypeArtifactId=teamcity-server-plugin -DarchetypeGroupId=org.jetbrains.teamcity.archetypes -DarchetypeVersion=RELEASE

【讨论】:

【参考方案2】:

正确的命令是

mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate -DarchetypeRepository=http://download.jetbrains.com/teamcity-repository -DarchetypeArtifactId=teamcity-server-plugin -DarchetypeGroupId=org.jetbrains.teamcity.archetypes -DarchetypeVersion=RELEASE

(使用固定版本的原型插件)

文档将相应更新。

【讨论】:

请检查您是否使用最新 TeamCity 构建的文档:confluence.jetbrains.com/display/TCD10/… 即使不是最新的文档,保留导致文档错误的命令又有什么意义?也许添加一个注释“这个命令不起作用,但我们还是出于某种原因提供了它”会有所帮助。用户对 Jetbrains 基础设施不熟悉,Google 引导他们到指令无效的页面,足以让他们离开。 9.0 文档也将很快更新。很抱歉给您带来不便,感谢您告知我们。【参考方案3】:

修改%M2_HOME%\conf\settings.xml中的镜像

<mirrors>
  <mirror>
    <id>google-maven-central</id>
    <name>Google Maven Central</name>
    <url>https://maven-central.storage.googleapis.com</url>
    <mirrorOf>central</mirrorOf>
  </mirror> 
</mirrors> 

这个答案是在以下位置找到的: https://***.com/a/42407332/1937339

【讨论】:

以上是关于TeamCity插件开发maven失败的主要内容,如果未能解决你的问题,请参考以下文章

Maven实战与原理分析:maven 自定义插件开发实战

Maven实战与原理分析:maven 自定义插件开发实战

maven和maven插件开发的心得总结(持续更新..)

Maven插件开发简明教程

Mavenmaven 插件开发实战

我应该使用啥版本的 Java 来开发我的 MOJO Maven 插件?