Maven Classifier (#11833)
* maven classifier * static imports * bumped up plugin versions Co-authored-by: s9m33r <no-reply>
This commit is contained in:
parent
e65fe9db25
commit
768e9ae387
@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>maven-classifier</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>maven-classifier-example-consumer</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>maven-classifier-example-provider</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>maven-classifier-example-provider</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<classifier>arbitrary</classifier>
|
||||
</dependency>
|
||||
<!-- For example purpose not building as it requires both JDK 8 and 11 executables on the build machine -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.baeldung</groupId>-->
|
||||
<!-- <artifactId>maven-classifier-example-provider</artifactId>-->
|
||||
<!-- <version>0.0.1-SNAPSHOT</version>-->
|
||||
<!-- <classifier>jdk11</classifier>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>maven-classifier-example-provider</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<classifier>sources</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>maven-classifier-example-provider</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<classifier>tests</classifier>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,17 @@
|
||||
|
||||
package com.baeldung.maven.classifier.consumer;
|
||||
|
||||
import com.baeldung.maven.dependency.classifier.provider.model.Car;
|
||||
import com.baeldung.maven.dependency.classifier.provider.model.PowerSource;
|
||||
|
||||
public class FuelStation {
|
||||
|
||||
public FuelStation.Zone refill(Car car) {
|
||||
return PowerSource.BATTERY.equals(car.getPowerSource()) ? FuelStation.Zone.BATTERY : FuelStation.Zone.UNKNOWN;
|
||||
}
|
||||
|
||||
public enum Zone {
|
||||
BATTERY,
|
||||
UNKNOWN
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.baeldung.maven.classifier.consumer;
|
||||
|
||||
import com.baeldung.maven.classifier.consumer.FuelStation.Zone;
|
||||
import com.baeldung.maven.dependency.classifier.provider.model.Car;
|
||||
import com.baeldung.maven.dependency.classifier.provider.stub.CarStub;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class FuelStationUnitTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Given fuel type battery When request for refill Then Return Battery Zone")
|
||||
public void givenFuelTypeBattery_whenRequestToRefill_thenReturnBatteryZone() {
|
||||
FuelStation fuelStation = new FuelStation();
|
||||
Car electricCar = CarStub.ELECTRIC_CAR;
|
||||
|
||||
assertEquals(Zone.BATTERY, fuelStation.refill(electricCar));
|
||||
}
|
||||
}
|
@ -0,0 +1,122 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<artifactId>maven-classifier</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>maven-classifier-example-provider</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<!-- <jdk.11.executable.path></jdk.11.executable.path>-->
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.10.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>JDK 8</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
<fork>true</fork>
|
||||
</configuration>
|
||||
</execution>
|
||||
<!-- For example purpose not building as it requires both JDK 8 and 11 executables on the build machine -->
|
||||
<!-- <execution>-->
|
||||
<!-- <id>JDK 11</id>-->
|
||||
<!-- <phase>compile</phase>-->
|
||||
<!-- <goals>-->
|
||||
<!-- <goal>compile</goal>-->
|
||||
<!-- </goals>-->
|
||||
<!-- <configuration>-->
|
||||
<!-- <fork>true</fork>-->
|
||||
<!-- <outputDirectory>${project.build.outputDirectory}_jdk11</outputDirectory>-->
|
||||
<!-- <executable>${jdk.11.executable.path}</executable>-->
|
||||
<!-- <source>8</source>-->
|
||||
<!-- <target>11</target>-->
|
||||
<!-- </configuration>-->
|
||||
<!-- </execution>-->
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>Arbitrary</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<classifier>arbitrary</classifier>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>Test Jar</id>
|
||||
<goals>
|
||||
<goal>test-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<!-- For example purpose not building as it requires both JDK 8 and 11 executables on the build machine -->
|
||||
<!-- <execution>-->
|
||||
<!-- <id>default-package-jdk11</id>-->
|
||||
<!-- <phase>package</phase>-->
|
||||
<!-- <goals>-->
|
||||
<!-- <goal>jar</goal>-->
|
||||
<!-- </goals>-->
|
||||
<!-- <configuration>-->
|
||||
<!-- <classesDirectory>${project.build.outputDirectory}_jdk11</classesDirectory>-->
|
||||
<!-- <classifier>jdk11</classifier>-->
|
||||
<!-- </configuration>-->
|
||||
<!-- </execution>-->
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.3.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1,14 @@
|
||||
package com.baeldung.maven.dependency.classifier.provider.factory;
|
||||
|
||||
import com.baeldung.maven.dependency.classifier.provider.model.Car;
|
||||
import com.baeldung.maven.dependency.classifier.provider.model.Car.Type;
|
||||
|
||||
public class CarFactory {
|
||||
|
||||
public static Car manufacture(Type carType) {
|
||||
Car car = new Car();
|
||||
car.setType(carType);
|
||||
|
||||
return car;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.baeldung.maven.dependency.classifier.provider.model;
|
||||
|
||||
public class Car {
|
||||
private Type type;
|
||||
private PowerSource fuelType;
|
||||
|
||||
public Type getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(Type carType) {
|
||||
this.type = carType;
|
||||
}
|
||||
|
||||
public PowerSource getPowerSource() {
|
||||
return this.fuelType;
|
||||
}
|
||||
|
||||
public void setFuelType(PowerSource fuelType) {
|
||||
this.fuelType = fuelType;
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
ELECTRIC
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.baeldung.maven.dependency.classifier.provider.model;
|
||||
|
||||
public enum PowerSource {
|
||||
BATTERY
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
|
||||
package com.baeldung.maven.dependency.classifier.provider.factory;
|
||||
|
||||
import com.baeldung.maven.dependency.classifier.provider.model.Car;
|
||||
import com.baeldung.maven.dependency.classifier.provider.model.Car.Type;
|
||||
import com.baeldung.maven.dependency.classifier.provider.model.PowerSource;
|
||||
import com.baeldung.maven.dependency.classifier.provider.stub.CarStub;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
class CarFactoryUnitTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Given Car type When CarFactory manufacture is called Then create a Car of the given type")
|
||||
public void givenCarType_whenCarFactoryManufactureCalled_thenCreateCarOfGivenType() {
|
||||
Car car = CarFactory.manufacture(Type.ELECTRIC);
|
||||
|
||||
assertNotNull(car, "CarFactory didn't manufacture a car. Car is null");
|
||||
assertEquals(Type.ELECTRIC, car.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Given an electric car When asked for fuel type Then return Battery")
|
||||
public void givenElectricCar_whenAskedForFuelType_thenReturnBattery() {
|
||||
Car car = CarStub.ELECTRIC_CAR;
|
||||
|
||||
assertEquals(PowerSource.BATTERY, car.getPowerSource());
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.baeldung.maven.dependency.classifier.provider.stub;
|
||||
|
||||
import com.baeldung.maven.dependency.classifier.provider.model.Car;
|
||||
import com.baeldung.maven.dependency.classifier.provider.model.PowerSource;
|
||||
import com.baeldung.maven.dependency.classifier.provider.model.Car.Type;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class CarStub {
|
||||
public static Car ELECTRIC_CAR = Mockito.mock(Car.class);
|
||||
|
||||
static {
|
||||
when(ELECTRIC_CAR.getType()).thenReturn(Type.ELECTRIC);
|
||||
when(ELECTRIC_CAR.getPowerSource()).thenReturn(PowerSource.BATTERY);
|
||||
}
|
||||
}
|
27
maven-modules/maven-classifier/pom.xml
Normal file
27
maven-modules/maven-classifier/pom.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>maven-classifier</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<modules>
|
||||
<module>maven-classifier-example-consumer</module>
|
||||
<module>maven-classifier-example-provider</module>
|
||||
</modules>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>maven-modules</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -36,6 +36,7 @@
|
||||
<module>maven-surefire-plugin</module>
|
||||
<module>maven-parent-pom-resolution</module>
|
||||
<module>maven-simple</module>
|
||||
<module>maven-classifier</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
|
Loading…
x
Reference in New Issue
Block a user