Skip to content

Gradle-ify the project to prepare for multi-module publishing #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ charset = utf-8
indent_style = space
indent_size = 4

[.github/workflows/*.yml]
[*.yml]
indent_size = 2
10 changes: 5 additions & 5 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2
updates:
- package-ecosystem: maven
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
- package-ecosystem: maven
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
7 changes: 3 additions & 4 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ jobs:
with:
distribution: temurin
java-version: '17'
cache: maven
cache: gradle

- name: 🏗️ Build & test
run: |
mvn -version
export MAVEN_HOME="$(whereis mvn)"
mvn clean verify -Dorg.slf4j.simpleLogger.showDateTime=true "-Dorg.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss"
./gradlew --version --no-daemon
./gradlew clean publishToMavenLocal -i --no-daemon --warning-mode all
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Maven
target/
pom.xml.tag
pom.xml.releaseBackup
Expand All @@ -10,6 +11,10 @@ buildNumber.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar

# Gradle
.gradle/
build/

# IntelliJ
.idea/
*.iml
21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

31 changes: 24 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Classpath modification extension for JUnit5

[![Build Status](https://travis-ci.com/fridujo/classpath-junit-extension.svg?branch=master)](https://travis-ci.com/fridujo/classpath-junit-extension)
[![Coverage Status](https://codecov.io/gh/fridujo/classpath-junit-extension/branch/master/graph/badge.svg)](https://codecov.io/gh/fridujo/classpath-junit-extension/)
[![Maven Central](https://img.shields.io/maven-central/v/com.github.fridujo/classpath-junit-extension.svg)](https://search.maven.org/#search|ga|1|a:"classpath-junit-extension")
Expand Down Expand Up @@ -48,29 +49,38 @@ void amqp_basic_get() {
```

## Alternatives
Use the `maven-invoker-plugin` with **pom.xml** template (see an example [here](https://github.com/fridujo/rabbitmq-mock/blob/78cd20380ea46089193dfbf5e29efd55798343ee/pom.xml#L163)).

Use the `maven-invoker-plugin` with **pom.xml** template (see an
example [here](https://github.com/fridujo/rabbitmq-mock/blob/78cd20380ea46089193dfbf5e29efd55798343ee/pom.xml#L163)).

## Roadmap
Currently this extension uses a _workaround_ to get things done, but it is waiting for [JUnit5 #201](https://github.com/junit-team/junit5/issues/201) to get a cleaner approach at this.

Currently this extension uses a _workaround_ to get things done, but it is waiting
for [JUnit5 #201](https://github.com/junit-team/junit5/issues/201) to get a cleaner approach at this.

Next things to do:

* Replace dependencies by other ones (different versions or implementations)
* Support other **Build Tools** (Gradle, SBT, Ivy, etc.)
* Make the annotation
* available at class level
* work in `@Nested` tests
* work in conjunction with **injection** / **test-templates** (may require **the classloader extension**)
* repeatable, so that the same test can be expected to work against various classpath (different version of a library per se)
* available at class level
* work in `@Nested` tests
* work in conjunction with **injection** / **test-templates** (may require **the classloader extension**)
* repeatable, so that the same test can be expected to work against various classpath (different version of a
library per se)

## Contribute

Any contribution is greatly appreciated.

[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#github.com/fridujo/classpath-junit-extension.git)

## Getting Started

### Maven

Add the following dependency to your **pom.xml**

```xml
<dependency>
<groupId>com.github.fridujo</groupId>
Expand All @@ -81,7 +91,9 @@ Add the following dependency to your **pom.xml**
```

### Gradle

Add the following dependency to your **build.gradle**

```groovy
repositories {
mavenCentral()
Expand All @@ -98,14 +110,17 @@ dependencies {

### Building from Source

You need [JDK-8+](http://jdk.java.net/8/) (at least) to build this extension. The project can be built with Maven using the following command.
You need [JDK-8+](http://jdk.java.net/8/) (at least) to build this extension. The project can be built with Maven using
the following command.

```
mvn clean package
```

### Installing in the Local Maven Repository

The project can be installed in a local Maven Repository for usage in other projects via the following command.

```
mvn clean install
```
Expand All @@ -115,6 +130,7 @@ mvn clean install
The master of the project pushes SNAPSHOTs in Sonatype's repo.

To use the latest master build add Sonatype OSS snapshot repository, for Maven:

```
<repositories>
...
Expand All @@ -126,6 +142,7 @@ To use the latest master build add Sonatype OSS snapshot repository, for Maven:
```

For Gradle:

```groovy
repositories {
// ...
Expand Down
34 changes: 34 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
group = "com.github.fridujo"
version = "1.0.1-SNAPSHOT"
description = "classpath-junit-extension"

allprojects {
repositories {
mavenLocal()
mavenCentral()
}

apply {
plugin("base")
}

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}

tasks.withType<Javadoc> {
options.encoding = "UTF-8"
(options as CoreJavadocOptions).addStringOption("Xdoclint:all,-missing", "-quiet")
}

tasks.withType<Test> {
useJUnitPlatform()
}
}

subprojects {
apply {
plugin("java")
plugin("java-library")
}
}
35 changes: 35 additions & 0 deletions classpath-junit-extension/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
plugins {
`maven-publish`
}

group = "com.github.fridujo"
version = "1.0.1-SNAPSHOT"

java {
withSourcesJar()
withJavadocJar()
}

publishing {
publications.create<MavenPublication>("maven") {
from(components["java"])
}
}

dependencies {
compileOnly(libs.org.apache.maven.resolver.maven.resolver.api)
compileOnly(libs.org.apache.maven.resolver.maven.resolver.spi)
compileOnly(libs.org.apache.maven.resolver.maven.resolver.impl)
compileOnly(libs.org.junit.jupiter.junit.jupiter.api)

api(libs.ch.qos.logback.logback.classic)
api(libs.eu.maveniverse.maven.mima.context)
api(libs.com.fasterxml.jackson.dataformat.jackson.dataformat.xml)

runtimeOnly(libs.eu.maveniverse.maven.mima.runtime.standalone.static)

testImplementation(libs.org.junit.jupiter.junit.jupiter)
testImplementation(libs.org.assertj.assertj.core)
testImplementation(libs.org.mockito.mockito.core)
testImplementation(libs.com.google.guava.guava)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ private PathElement(String rawPath) {
public static PathElement create(String rawPath) {
String normalizedRawPath = rawPath;

normalizedRawPath = normalizedRawPath.replace("\\\\", "\\");

boolean directory = Files.isDirectory(Paths.get(rawPath));
boolean alreadyHasTerminalSlash = rawPath.trim().endsWith(File.separator);
if (directory && !alreadyHasTerminalSlash) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* <li><b>groupId:artifactId:version</b></li>
* </ul>
* <p>
* <p>
* In opposition to {@link #excludeDependencies()}, their will be no attempt to list and exclude dependencies.
*/
String[] excludeJars() default {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void exclusion_of_multiple_gavs_and_their_dependencies() {
}

@Test
@ModifiedClasspath(excludeDependencies = "guava:guava")
@ModifiedClasspath(excludeDependencies = "com.google.guava:guava")
void exclusion_of_one_gav_and_its_dependencies() {
assertThatExceptionOfType(ClassNotFoundException.class)
.isThrownBy(() -> Class.forName("com.google.common.collect.Maps"));
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sourceCompatibility=17
30 changes: 30 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file was generated by the Gradle 'init' task.
# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format

[versions]
ch-qos-logback-logback-classic = "1.5.3"
com-fasterxml-jackson-dataformat-jackson-dataformat-xml = "2.17.0"
com-google-guava-guava = "32.1.2-jre"
eu-maveniverse-maven-mima-context = "2.4.10"
eu-maveniverse-maven-mima-runtime-standalone-static = "2.4.10"
org-apache-maven-resolver-maven-resolver-api = "1.9.18"
org-apache-maven-resolver-maven-resolver-impl = "1.9.18"
org-apache-maven-resolver-maven-resolver-spi = "1.9.18"
org-assertj-assertj-core = "3.25.3"
org-junit-jupiter-junit-jupiter = "5.10.2"
org-junit-jupiter-junit-jupiter-api = "5.10.2"
org-mockito-mockito-core = "5.11.0"

[libraries]
ch-qos-logback-logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "ch-qos-logback-logback-classic" }
com-fasterxml-jackson-dataformat-jackson-dataformat-xml = { module = "com.fasterxml.jackson.dataformat:jackson-dataformat-xml", version.ref = "com-fasterxml-jackson-dataformat-jackson-dataformat-xml" }
com-google-guava-guava = { module = "com.google.guava:guava", version.ref = "com-google-guava-guava" }
eu-maveniverse-maven-mima-context = { module = "eu.maveniverse.maven.mima:context", version.ref = "eu-maveniverse-maven-mima-context" }
eu-maveniverse-maven-mima-runtime-standalone-static = { module = "eu.maveniverse.maven.mima.runtime:standalone-static", version.ref = "eu-maveniverse-maven-mima-runtime-standalone-static" }
org-apache-maven-resolver-maven-resolver-api = { module = "org.apache.maven.resolver:maven-resolver-api", version.ref = "org-apache-maven-resolver-maven-resolver-api" }
org-apache-maven-resolver-maven-resolver-impl = { module = "org.apache.maven.resolver:maven-resolver-impl", version.ref = "org-apache-maven-resolver-maven-resolver-impl" }
org-apache-maven-resolver-maven-resolver-spi = { module = "org.apache.maven.resolver:maven-resolver-spi", version.ref = "org-apache-maven-resolver-maven-resolver-spi" }
org-assertj-assertj-core = { module = "org.assertj:assertj-core", version.ref = "org-assertj-assertj-core" }
org-junit-jupiter-junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "org-junit-jupiter-junit-jupiter" }
org-junit-jupiter-junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "org-junit-jupiter-junit-jupiter-api" }
org-mockito-mockito-core = { module = "org.mockito:mockito-core", version.ref = "org-mockito-mockito-core" }
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading