Maven:配置文件激活取决于 localRepository 属性?

发布于 2024-12-03 02:18:25 字数 1556 浏览 0 评论 0原文

在 Maven 中,我只想在工件尚未安装到存储库时才执行构建。我的想法是使用默认情况下处于非活动状态的配置文件,但如果工件丢失,则会被激活。 到目前为止我还没有成功,因为Maven属性似乎不能用于配置文件激活?

settings.xml:

...
<localRepository>/local/m2repo</localRepository>
...

1)这有效:

pom.xml:

...
<profile>
    <id>my-profile</id>
    <activation>
        <activeByDefault>false</activeByDefault>
        <file>
            <missing>/local/m2repo/something</missing>
        </file>
    </activation>
    ...
</profile>

2)这不起作用:

pom.xml:

...
<profile>
    <id>my-profile</id>
    <activation>
        <activeByDefault>false</activeByDefault>
        <file>
            <missing>${settings.localRepository}/something</missing>
        </file>
    </activation>
    ...
</profile>

3)这也不起作用:

settings.xml:

...
<properties>
    <local.repository>${settings.localRepository}</local.repository>
</properties>
...

pom.xml:

<profile>
    <id>my-profile</id>
    <activation>
        <activeByDefault>false</activeByDefault>
        <file>
            <missing>${local.repository}/something</missing>
        </file>
    </activation>
</profile>

是否有某种解决方法或替代方法我可以检查我的工件是否存在,并且仅在必要时运行构建? 感谢您的任何想法!

in Maven I want to execute a build only if the artifact has not yet been installed to the repository. My idea is to use a profile which is inactive by default, but will be activated if the artifact is missing.
So far I was not successful because it seems that Maven properties cannot be used for profile activation?

settings.xml:

...
<localRepository>/local/m2repo</localRepository>
...

1) This works:

pom.xml:

...
<profile>
    <id>my-profile</id>
    <activation>
        <activeByDefault>false</activeByDefault>
        <file>
            <missing>/local/m2repo/something</missing>
        </file>
    </activation>
    ...
</profile>

2) This doesn't work:

pom.xml:

...
<profile>
    <id>my-profile</id>
    <activation>
        <activeByDefault>false</activeByDefault>
        <file>
            <missing>${settings.localRepository}/something</missing>
        </file>
    </activation>
    ...
</profile>

3) This won't work either:

settings.xml:

...
<properties>
    <local.repository>${settings.localRepository}</local.repository>
</properties>
...

pom.xml:

<profile>
    <id>my-profile</id>
    <activation>
        <activeByDefault>false</activeByDefault>
        <file>
            <missing>${local.repository}/something</missing>
        </file>
    </activation>
</profile>

Is there somehow a workaround or alternative how I can check for the existence of my artifact and only run a build if necessary?
Thanks for any ideas!

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

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

发布评论

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

评论(1

很糊涂小朋友 2024-12-10 02:18:25

你不能那样做。

激活文件位置通常相对于当前项目文件夹。

仅在配置文件已定义并开始构建后才会计算属性。

You can't do that.

The activation file location normally are relative to the current project folder.

The properties will be calculated only after the profiles are already defined and build started.

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