未连接到公司 VPN / 私有存储库时 Maven 无法构建?

Maven failing to build when not connected to company VPN / private repository?

目前有很多人在家工作并使用 VPN,我在为不使用与工作相关的人工制品的个人项目构建 Maven 时遇到了问题。

这导致我总是需要连接到 VPN。

例如,如果我创建一个新的 spring 引导应用程序,它要求我在 VPN 上,否则它将无法正确构建,并出现如下错误:

Failed to read artifact descriptor for com.hubspot.slack:slack-base:jar:1.8: Could not transfer artifact com.hubspot.slack:slack-base:pom:1.8 from/to at-repository (https://foobar.jfrog.io/foobar/public): Access denied to: https://foobar.jfrog.io/foobar/public/com/hubspot/slack/slack-base/1.8/slack-base-1.8.pom

有没有办法让我配置 Maven 来尝试构建而不需要我的公司存储库?

或者我可以有多个配置以及在它们之间切换的方法吗?

我知道它应该因 foocompany 特定的人工制品而失败,但不会因其他所有东西而失败。

这是 config.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>foo-repository</id>
            <url>https://foo.jfrog.io/foo/public</url>
            <mirrorOf>*</mirrorOf>
        </mirror>
    </mirrors>

    <servers>
        <server>
            <id>foo-repository</id>
            <username>deployment</username>
            <password>xxx</password>
        </server>
        <server>
            <id>snapshots</id>
            <username>deployment</username>
            <password>xxx</password>
        </server>
        <server>
            <id>releases</id>
            <username>deployment</username>
            <password>xxx</password>
        </server>
    </servers>

    <profiles>
        <profile>
            <id>default</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>

            <repositories>
                <repository>
                    <id>foo-repository</id>
                    <url>This has to be populated but the URL will be taken from the mirror.</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>

            <pluginRepositories>
                <pluginRepository>
                    <id>foo-repository</id>
                    <url>This has to be populated but the URL will be taken from the mirror.</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
</settings>

本质上是像这样禁用用户 maven 配置并使用 bash 别名使其更容易的情况

#turn off default settings
mv ~/.m2/settings.xml ~/.m2/settings.xml.off

#turn on again
mv ~/.m2/settings.xml.off ~/.m2/settings.xml

可以在此处查看有关我的解决方法的更多信息:

https://tomaytotomato.com/maven-whilst-working-from-home/