Maven 原型目录:指定自定义位置

发布于 2024-11-18 17:33:39 字数 739 浏览 2 评论 0原文

我正在为 Maven 部署 Nexus 存储库,并在其上部署自定义原型。

我想执行 mvn archetype:generate 并提示内部 + 自定义原型列表。

我发现提示自定义原型的唯一方法(以符合人体工程学的方式,意味着没有 URL)是将原型目录路径定义为设置中的属性。这不是一个有效的解决方案,因为我想要多个目录(并且无法在 CLI 中覆盖此属性)。

有人知道如何做到这一点吗?

预先感谢,


[编辑] 我发现了相关的问题报告:http://jira.codehaus.org/browse/ARCHETYPE-273< /a>

我注意到在 archetype:generate 期间,maven 尝试访问中央存储库:

[DEBUG] Searching for remote catalog: http://repo1.maven.org/maven2/archetype-catalog.xml
[DEBUG] Searching for remote catalog: http://repo1.maven.org/maven2

它以“连接超时”结束,因为我没有(也不想)指定代理...

我不明白为什么maven不检查nexus目录...

I'm deploying a Nexus repository for Maven, and custom archetypes on it.

I would like to execute mvn archetype:generate and be prompted a list of internal + custom archetypes.

The only way I found to prompt custom archetypes (in an ergonomic way, meaning no URL) is to define the archetype-catalog path as a property in the settings. This is not a valid solution because I want several catalogs (and this property cannot be overriden in CLI).

Does anybody have a clue on how to do that ?

Thanks in advance,


[EDIT]
I found an issue report related : http://jira.codehaus.org/browse/ARCHETYPE-273

And I noticed that during archetype:generate, maven tries to reach the central repository :

[DEBUG] Searching for remote catalog: http://repo1.maven.org/maven2/archetype-catalog.xml
[DEBUG] Searching for remote catalog: http://repo1.maven.org/maven2

It ends by a "Connection Timed out" because I did not (and don't want to) specify a proxy...

I don't understand why maven doesn't check nexus catalog...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

终止放荡 2024-11-25 17:33:39

我还配置了一个 Nexus 来镜像 Maven 存储库,从而镜像远程目录。

<mirror>
    <!--This sends everything else to /public -->
    <id>nexus</id>
    <mirrorOf>*</mirrorOf>
    <url>http://afbwt03:8081/nexus/content/groups/JavaRepo/</url>
</mirror>

并且:

<profile>
    <id>nexus</id>
    <repositories>
        <repository>
            <id>central</id>
            <url>http://central</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <url>http://central</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
</profile>

只有当我使用以下 Maven 命令行时,我才能访问远程目录:

mvn archetype:generate -DarchetypeCatalog=http://afbwt03:8081/nexus/content/groups/JavaRepo

如果我没有定义 archetypeCatalog 变量,我会得到与您相同的行为:尝试访问回购1。 ...虽然配置了一些镜像。

I also have a Nexus configured to mirror the Maven repositories and thus the remote catalog too.

<mirror>
    <!--This sends everything else to /public -->
    <id>nexus</id>
    <mirrorOf>*</mirrorOf>
    <url>http://afbwt03:8081/nexus/content/groups/JavaRepo/</url>
</mirror>

and:

<profile>
    <id>nexus</id>
    <repositories>
        <repository>
            <id>central</id>
            <url>http://central</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <url>http://central</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
</profile>

I am able to access the remote catalog only when I use the following Maven command line:

mvn archetype:generate -DarchetypeCatalog=http://afbwt03:8081/nexus/content/groups/JavaRepo

If I don't define the archetypeCatalog variable, I get the same behavior as you do: trying to access the repo1. ... although some mirrors are configured.

童话里做英雄 2024-11-25 17:33:39

您需要

  • 在 .m2/settings.xml 的活动配置文件中定义

    属性archetypeRepository

  • 存储库和pluginRepositories重定向到您的镜像,位于相同的ID“central”上。

  • 当然,镜像定义

archetype 插件上镜像定义的 Apache maven 文档指定 archetypeRepository 是可定义的用户属性:
http://maven.apache.org/archetype/maven-archetype -plugin/generate-mojo.html

您的 .m2/settings.xml 应该包含这些最少的元素

<?xml version="1.0" encoding="UTF-8"?>

<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 http://maven.apache.org/xsd/settings-1.0.0.xsd">


  <mirrors>
      <mirror>
        <id>central</id>
        <name>Mirror for maven central</name>
        <url>http://mymvnhost:8081/nexus/content/groups/public/</url>
        <mirrorOf>*</mirrorOf>
      </mirror>

  </mirrors>

  <profiles>
    <profile>
      <id>dev</id>

        <properties>
        <archetypeRepository>http://mymvnhost:8081/nexus/content/groups/public/</archetypeRepository>
        </properties>

        <repositories>
            <repository>
              <id>central</id>
              <url>http://central</url>
              <releases><enabled>true</enabled></releases>
              <snapshots><enabled>true</enabled></snapshots>
            </repository>
        </repositories>

        <pluginRepositories>
            <pluginRepository>
              <id>central</id>
              <url>http://central</url>
              <releases><enabled>true</enabled></releases>
              <snapshots><enabled>true</enabled></snapshots>
            </pluginRepository>
        </pluginRepositories>

    </profile>
  </profiles>

  <activeProfiles>
    <activeProfile>dev</activeProfile>
  </activeProfiles>
</settings>

You need to have

  • the property archetypeRepository defined in the active profile in your .m2/settings.xml

  • the repositories and pluginRepositories redirected to your mirror, on the same id "central".

  • and of course, the mirror defined

Apache maven documentation on archetype plugin specifies that archetypeRepository is definable user property:
http://maven.apache.org/archetype/maven-archetype-plugin/generate-mojo.html

Your .m2/settings.xml should have these minimal elements

<?xml version="1.0" encoding="UTF-8"?>

<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 http://maven.apache.org/xsd/settings-1.0.0.xsd">


  <mirrors>
      <mirror>
        <id>central</id>
        <name>Mirror for maven central</name>
        <url>http://mymvnhost:8081/nexus/content/groups/public/</url>
        <mirrorOf>*</mirrorOf>
      </mirror>

  </mirrors>

  <profiles>
    <profile>
      <id>dev</id>

        <properties>
        <archetypeRepository>http://mymvnhost:8081/nexus/content/groups/public/</archetypeRepository>
        </properties>

        <repositories>
            <repository>
              <id>central</id>
              <url>http://central</url>
              <releases><enabled>true</enabled></releases>
              <snapshots><enabled>true</enabled></snapshots>
            </repository>
        </repositories>

        <pluginRepositories>
            <pluginRepository>
              <id>central</id>
              <url>http://central</url>
              <releases><enabled>true</enabled></releases>
              <snapshots><enabled>true</enabled></snapshots>
            </pluginRepository>
        </pluginRepositories>

    </profile>
  </profiles>

  <activeProfiles>
    <activeProfile>dev</activeProfile>
  </activeProfiles>
</settings>
风和你 2024-11-25 17:33:39

使用maven-archetype-plugin:3.1.1,您必须

  • 在存储库上添加/编辑archetype-catalog.xml,以列出您的自定义原型
  • 并编辑您的设置。使用 id archetype 添加此存储库。
  • mvn archetype:generate -DarchetypeCatalog=remote

https://maven.apache.org/archetype/maven-archetype-plugin/generate-mojo.html

如果您希望目录来自不同的存储库,请将以下内容添加到您的 settings.xml

<预><代码><存储库>;
原型
https://repository.domain.com/path/to/repo/

With maven-archetype-plugin:3.1.1 you have to

  • add/edit archetype-catalog.xml on your repo to list your custom archetypes
  • edit your settings.xml to add this repo with id archetype.
  • invoke mvn archetype:generate -DarchetypeCatalog=remote

From https://maven.apache.org/archetype/maven-archetype-plugin/generate-mojo.html :

If you want the catalogs to come from a different repository, please add the following to your settings.xml

<repository>
  <id>archetype</id>
  <url>https://repository.domain.com/path/to/repo/</url>
</repository>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文