Skip to content

Commit

Permalink
feat: introduce type 'fatjar' (#1800)
Browse files Browse the repository at this point in the history
* Use latest MIMA and introduce type 'fatjar'

A new ArtifactType that is also present in Maven4.
The 'fatjar' type denotes a Java JAR file that is
"self sufficient", contains all the dependencies.
This makes resolver stop.

Fixes #1778

Alows something like this
$ jbang eu.maveniverse.maven.plugins:toolbox:cli:0.1.9@fatjar

* doc: document fatjar option

---------

Co-authored-by: Max Rydahl Andersen <[email protected]>
  • Loading branch information
cstamas and maxandersen authored Jul 6, 2024
1 parent a2ef5a7 commit ccdae1d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ dependencies {
implementation "org.slf4j:jcl-over-slf4j:1.7.30"
implementation "org.jboss:jandex:2.2.3.Final"

implementation "eu.maveniverse.maven.mima:context:2.4.4"
runtimeOnly "eu.maveniverse.maven.mima.runtime:standalone-static:2.4.4"
implementation "eu.maveniverse.maven.mima:context:2.4.12"
runtimeOnly "eu.maveniverse.maven.mima.runtime:standalone-static:2.4.12"

testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.10.1"
testImplementation "org.junit.jupiter:junit-jupiter:5.10.1"
Expand Down Expand Up @@ -235,6 +235,7 @@ compileJava9Java {
shadowJar {
minimize() {
//exclude(dependency('org.slf4j:slf4j-api:.*'))
exclude(dependency('eu.maveniverse.maven.mima:context:.*'))
exclude(dependency('eu.maveniverse.maven.mima.runtime:standalone-static:.*'))
exclude(dependency('org.slf4j:jcl-over-slf4j:.*'))
exclude(dependency('org.slf4j:slf4j-nop:.*'))
Expand Down
12 changes: 12 additions & 0 deletions docs/modules/ROOT/pages/dependencies.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ is the equivalent of the following Maven dependency declaration:
```
====

== 'fatjar' dependencies [Experimental]

Maven 4 introduces a special dependency type called `fatjar` which can be used to designate that the dependency should be treated as a jar that have all its dependencies included and thus not require fetching declared dependencies.

JBang 0.117 adds support for this allowing you to just add `@fatjar` at the end.

Example:

`jbang eu.maveniverse.maven.plugins:toolbox:0.1.9:cli@fatjar`

Without `@fatjar` it would resolve dependencies which would be redundant.

== Managed dependencies ("BOM POM"'s) [Experimental]

When using libraries and frameworks it can get tedious to mange and update multiple versions.
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/dev/jbang/dependencies/ArtifactResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.ArtifactType;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.artifact.DefaultArtifactType;
import org.eclipse.aether.collection.CollectRequest;
import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.metadata.Metadata;
Expand Down Expand Up @@ -146,6 +147,9 @@ private ArtifactResolver(Builder builder) {
: null)
.repositoryListener(listener);

overridesBuilder.extraArtifactTypes(
Collections.singletonList(new DefaultArtifactType("fatjar", "jar", null, "java", true, true)));

this.context = Runtimes.INSTANCE.getRuntime().create(overridesBuilder.build());
}

Expand Down Expand Up @@ -354,6 +358,8 @@ private Artifact toArtifact(MavenCoordinate coord) {
if (type != null) {
ext = type.getExtension();
cls = Optional.ofNullable(cls).orElse(type.getClassifier());
return new DefaultArtifact(coord.getGroupId(), coord.getArtifactId(), cls, ext, coord.getVersion(),
type);
}
}
return new DefaultArtifact(coord.getGroupId(), coord.getArtifactId(), cls, ext, coord.getVersion());
Expand Down

0 comments on commit ccdae1d

Please sign in to comment.