Skip to content

Commit

Permalink
GH-17 - Switch to Java 11 for the examples.
Browse files Browse the repository at this point in the history
Tweak build to only include the examples module when running on JDK 11. Tweaked CI build to build everything but the examples on JDK 8 followed by a JDK 11 based build of the sample.
  • Loading branch information
odrotbohm committed Feb 25, 2021
1 parent 0f18f5e commit 325b711
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 11 deletions.
25 changes: 24 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
build:

name: Build project
runs-on: ubuntu-latest

steps:
Expand All @@ -29,3 +29,26 @@ jobs:
- name: Build with Maven
run: mvn -B package --file pom.xml

build-examples:
name: Build examples
runs-on: ubuntu-latest

steps:

- uses: actions/checkout@v2

- name: Set up JDK 8
uses: actions/setup-java@v1
with:
java-version: 8

- uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build with Maven
run: mvn -B package --file jmolecules-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.jmolecules.examples.jpa;

import org.jmolecules.examples.jpa.customer.Address;
import org.jmolecules.examples.jpa.customer.Customer;
import org.jmolecules.examples.jpa.customer.Customers;
import org.jmolecules.examples.jpa.order.Order;
Expand All @@ -33,11 +34,13 @@ public static void main(String[] args) {

ApplicationContext context = SpringApplication.run(Application.class, args);

Customers customers = context.getBean(Customers.class);
Customer customer = customers.save(new Customer("Dave", "Matthews"));
var address = new Address("41 Greystreet", "Dreaming Tree", "2731");

Orders orders = context.getBean(Orders.class);
Order order = orders.save(new Order(customer));
var customers = context.getBean(Customers.class);
var customer = customers.save(new Customer("Dave", "Matthews", address));

var orders = context.getBean(Orders.class);
var order = orders.save(new Order(customer));

customers.resolveRequired(order.getCustomer());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
public class Address implements Entity<Customer, Address.AddressId> {

private Address.AddressId id;
private final String street, city, zipCode;

public Address(String street, String city, String zipCode) {

this.id = AddressId.of(UUID.randomUUID());
this.street = street;
this.city = city;
this.zipCode = zipCode;
}

@Value(staticConstructor = "of")
public static class AddressId implements Identifier {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
package org.jmolecules.examples.jpa.customer;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Value;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.jmolecules.ddd.types.AggregateRoot;
import org.jmolecules.ddd.types.Association;
import org.jmolecules.ddd.types.Identifier;
import org.jmolecules.examples.jpa.customer.Customer.CustomerId;
import org.springframework.util.Assert;

/**
* @author Oliver Drotbohm
Expand All @@ -37,15 +38,20 @@ public class Customer implements AggregateRoot<Customer, CustomerId> {
private String firstname, lastname;
private List<Address> addresses;

public Customer(String firstname, String lastname) {
public Customer(String firstname, String lastname, Address address) {

Assert.notNull(address, "Address must not be null!");

this.id = CustomerId.of(UUID.randomUUID());

this.firstname = firstname;
this.lastname = lastname;

this.addresses = new ArrayList<>();
this.addresses.add(address);
}

@Value
@RequiredArgsConstructor(staticName = "of")
@Value(staticConstructor = "of")
public static class CustomerId implements Identifier {
private final UUID id;
}
Expand Down
18 changes: 17 additions & 1 deletion jmolecules-examples/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand All @@ -15,4 +17,18 @@
<module>jmolecules-spring-data-jpa</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>

</project>
10 changes: 9 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,18 @@
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>jmolecules-examples</module>
<module>jmolecules-bytebuddy-empty</module>
</modules>
</profile>
<profile>
<id>java-11</id>
<activation>
<jdk>11</jdk>
</activation>
<modules>
<module>jmolecules-examples</module>
</modules>
</profile>
<profile>
<id>sonatype</id>
<properties>
Expand Down

0 comments on commit 325b711

Please sign in to comment.