Skip to content

Commit 94e0317

Browse files
NjabuloMNjabulo Mwandla
andauthored
BAEL-6914: Define Multiple Repositories with Maven (#16751)
* BAEL-6914: Define Multiple Repositories with Maven * BAEL-6914: Define Multiple Repositories with Maven * BAEL-6914: Define Multiple Repositories with Maven * BAEL-6914: Define Multiple Repositories with Maven --------- Co-authored-by: Njabulo Mwandla <[email protected]>
1 parent e6e0248 commit 94e0317

File tree

7 files changed

+168
-0
lines changed

7 files changed

+168
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<artifactId>maven-multiple-repositories</artifactId>
7+
<version>0.0.1</version>
8+
<packaging>jar</packaging>
9+
10+
<parent>
11+
<groupId>com.baeldung</groupId>
12+
<artifactId>maven-modules</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
</parent>
15+
16+
<repositories>
17+
<repository>
18+
<id>internal-maven-repo</id>
19+
<name>Internal Repository</name>
20+
<url>https://host/internal-maven-packages</url>
21+
</repository>
22+
<repository>
23+
<id>central</id>
24+
<name>Central Repository</name>
25+
<url>https://repo.maven.apache.org/maven2</url>
26+
</repository>
27+
</repositories>
28+
29+
<build>
30+
<finalName>GreeterExampleService</finalName>
31+
<plugins>
32+
<plugin>
33+
<groupId>org.apache.maven.plugins</groupId>
34+
<artifactId>maven-compiler-plugin</artifactId>
35+
<configuration>
36+
<source>${maven.compiler.source}</source>
37+
<target>${maven.compiler.target}</target>
38+
</configuration>
39+
</plugin>
40+
</plugins>
41+
</build>
42+
43+
<properties>
44+
<maven.compiler.source>17</maven.compiler.source>
45+
<maven.compiler.target>17</maven.compiler.target>
46+
</properties>
47+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.baeldung.internal.repo.sample;
2+
3+
public class GreeterServiceExample {
4+
public Greeting greetInYourLanguage(String language) {
5+
return switch (language.toLowerCase()) {
6+
case "english" -> new Greeting("Hello", new Language("English", "en"));
7+
case "spanish" -> new Greeting("Hola", new Language("Spanish", "es"));
8+
case "xhosa" -> new Greeting("Molo", new Language("Xhosa", "xh"));
9+
default -> null;
10+
};
11+
}
12+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.baeldung.internal.repo.sample;
2+
3+
public class Greeting {
4+
private String value;
5+
private Language language;
6+
7+
public Greeting(String value, Language language) {
8+
this.value = value;
9+
this.language = language;
10+
}
11+
12+
public String getValue() {
13+
return value;
14+
}
15+
16+
public void setValue(String value) {
17+
this.value = value;
18+
}
19+
20+
public Language getLanguage() {
21+
return language;
22+
}
23+
24+
public void setLanguage(Language language) {
25+
this.language = language;
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.baeldung.internal.repo.sample;
2+
3+
public class Language {
4+
private String name;
5+
private String code;
6+
7+
public Language(String name, String code) {
8+
this.name = name;
9+
this.code = code;
10+
}
11+
12+
public String getName() {
13+
return name;
14+
}
15+
16+
public void setName(String name) {
17+
this.name = name;
18+
}
19+
20+
public String getCode() {
21+
return code;
22+
}
23+
24+
public void setCode(String code) {
25+
this.code = code;
26+
}
27+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
5+
6+
<servers>
7+
<server>
8+
<id>internal-maven-repo</id>
9+
<username>username</username>
10+
<password>passphrase_or_token</password>
11+
</server>
12+
</servers>
13+
14+
<profiles>
15+
<profile>
16+
<id>local-dev</id>
17+
<repositories>
18+
<repository>
19+
<id>internal-maven-repo</id>
20+
<name>Internal Repository</name>
21+
<url>https://host/internal-maven-packages</url>
22+
</repository>
23+
<repository>
24+
<id>central</id>
25+
<name>Central Repository</name>
26+
<url>https://repo.maven.apache.org/maven2</url>
27+
</repository>
28+
</repositories>
29+
</profile>
30+
</profiles>
31+
32+
<activeProfiles>
33+
<activeProfile>local-dev</activeProfile>
34+
</activeProfiles>
35+
</settings>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.baeldung;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import org.junit.jupiter.api.Test;
6+
import com.baeldung.internal.repo.sample.GreeterServiceExample;
7+
import com.baeldung.internal.repo.sample.Greeting;
8+
9+
public class GreeterServiceUsageUnitTest {
10+
@Test
11+
public void whenGreetingInEnglish_thenAnENCodeShouldBeMadeAvailable() {
12+
GreeterServiceExample greeterService
13+
= new GreeterServiceExample();
14+
Greeting englishGreeting
15+
= greeterService.greetInYourLanguage("English");
16+
assertEquals(
17+
"en", englishGreeting.getLanguage().getCode());
18+
}
19+
}

maven-modules/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
<module>maven-pom-types</module>
5353
<module>multimodulemavenproject</module>
5454
<module>resume-from</module>
55+
<module>maven-multiple-repositories</module>
5556
</modules>
5657

5758
<dependencyManagement>

0 commit comments

Comments
 (0)