Hirantha
Hirantha

Reputation: 337

How to maintain two maven profiles for local maven installation?

I use my local machine for my development works in my office (Software Company currently I am working for). They have a different maven settings. It directs to their own maven repositories. But, for my own work at home I want to access default maven settings.

So, How can I achieve this? Will it be possible to do this by maintaining two separate maven profiles for office and my own works?

Company specific configuration has defined some servers and repositories. How should I configure the settings.xml file to connect default maven repository when I am working at home without maintaining separate settings.xml files?

Upvotes: 0

Views: 442

Answers (1)

Anton Koscejev
Anton Koscejev

Reputation: 4847

Yes, you can use one ~/.m2/settings.xml file for both. Below is an example of what I'm using. Servers are outside of profiles, since they are only used when referenced by ID.

In my IDE I have comp profile enabled for company projects, atlassian profile for atlassian SDK projects, and none of them for other projects. In IntelliJ IDEA you can do this via sidebar, while in Eclipse you have to do this via Project Properties. From command-line you'll have to activate them manually via -P. However, you can experiment with property-based automatic profile activation.

<?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">
    <servers>
        <server>
            <id>comp-releases</id>
            <username>me</username>
            <password>secret</password>
        </server>
        <server>
            <id>comp-snapshots</id>
            <username>me</username>
            <password>secret</password>
        </server>
    </servers>

    <profiles>
        <profile>
            <id>comp</id>
            <repositories>
                <repository>
                    <id>comp-nexus</id>
                    <name>Nexus Public</name>
                    <url>https://www.example.com/nexus/content/groups/public/</url>
                </repository>
            </repositories>
        </profile>
        <profile>
            <id>atlassian</id>
            <repositories>
                <repository>
                    <id>atlassian-public</id>
                    <url>https://maven.atlassian.com/repository/public</url>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>atlassian-public</id>
                    <url>https://maven.atlassian.com/repository/public</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <updatePolicy>never</updatePolicy>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
</settings>

Upvotes: 1

Related Questions