/pof-gradle-demo-multi-project

Using the Coherence Gradle POF Plugin with multi-project Gradle builds

Primary LanguageJavaApache License 2.0Apache-2.0

POF Gradle Demo Multi-Project

Using the Coherence Gradle POF Plugin with multi-project Gradle builds.

As a starting point we use the Gradle init task to create a multi-project build. This is the same example provided at Building Java Applications with libraries Sample in the Gradle documentation.

Create Gradle Project Structure

gradle init
Select type of project to generate:
  1: basic
  2: application
  3: library
  4: Gradle plugin
Enter selection (default: basic) [1..4] 2
Select implementation language:
  1: C++
  2: Groovy
  3: Java
  4: Kotlin
  5: Scala
  6: Swift
Enter selection (default: Java) [1..6] 3
Generate multiple subprojects for application? (default: no) [yes, no] yes
Select build script DSL:
  1: Kotlin
  2: Groovy
Enter selection (default: Kotlin) [1..2] 2
Project name (default: pof-gradle-demo-multi-project): pof-gradle-demo-multi-project
Source package (default: pof.gradle.demo.multi.project): com.hillert.coherence.pof
Enter target version of Java (min. 7) (default: 21): 21
Generate build using new APIs and behavior (some features may change in the next minor release)? (default: no) [yes, no] no

Add Coherence POF Plugin

To App module

We will use a snapshot version of the Coherence POF plugin. To do this we need to add the Sonatype snapshot repository to settings.gradle in the root of the project.

settings.gradle (root)
pluginManagement {
    repositories {
        mavenLocal()
        maven {
            url 'https://oss.sonatype.org/content/repositories/snapshots/'
        }
        gradlePluginPortal()
    }
}

Now we can add the Coherence POF plugin to the app module. In ./app/build.gradle add the following:

build.gradle (app module)
plugins {
    id 'com.hillert.coherence.pof.java-application-conventions'
    id 'com.oracle.coherence.ce' version '24.03-SNAPSHOT'
}

...

compileTestJava {
    dependsOn('coherencePof')
}
Note
24.03-SNAPSHOT contains a regression. By default compileTestJava should depend on coherencePof but this is not the case right now. Therefore, we need to add the dependsOn line explicitly.

To Utilities module

Let’s decide to add the Coherence POF plugin to the utilities module instead, as we decide to keep our POF annotated classes in the utilities module. Therefore, move the Coherence POF plugin declaration to ./utilities/build.gradle:

build.gradle (app module)
plugins {
    id 'com.hillert.coherence.pof.java-application-conventions'
    id 'com.oracle.coherence.ce' version '24.03-SNAPSHOT'
}

dependencies {
    api project(':list')
    implementation('com.oracle.coherence.ce:coherence:23.09');
}

compileTestJava {
    dependsOn('coherencePof')
}

We will also add a dependency on the Coherence library to the utilities module. Next we will add a basic POF annotated class to the utilities module:

PofClass.java (utilities module)
package com.hillert.coherence.pof.utilities;

import com.tangosol.io.pof.schema.annotation.PortableType;

@PortableType(id=1000)
public class PofClass {
	private String name;

	public PofClass(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}
}

One thing that is missing is a dependency on the utilities module’s coherencePof from the app module. Add the following to ./app/build.gradle:

build.gradle (app module)
compileJava {
    dependsOn(':utilities:coherencePof')
}
Note
24.03-SNAPSHOT contains a regression in this regard. By default, a child module with a compileJava should automatically depend on coherencePof but this is not the case right now. Therefore, we need to add the dependsOn line explicitly.