Skip to content

Commit

Permalink
Merge branch 'api-10' into api-11
Browse files Browse the repository at this point in the history
  • Loading branch information
aromaa committed Jan 4, 2024
2 parents 49d3e1d + 80faee9 commit d035468
Show file tree
Hide file tree
Showing 130 changed files with 2,162 additions and 2,047 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,23 @@
package org.spongepowered.gradle.impl;

import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ModuleDependency;
import org.gradle.api.artifacts.ModuleIdentifier;
import org.gradle.api.artifacts.ResolvedArtifact;
import org.gradle.api.artifacts.component.ComponentIdentifier;
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.api.logging.Logger;
import org.gradle.api.tasks.SourceSet;

import javax.annotation.Nullable;
import javax.inject.Inject;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -51,6 +60,39 @@ public SpongeImplementationExtension(final Project project, final Logger logger)
this.logger = logger;
}

public void copyModulesExcludingProvided(final Configuration source, final Configuration provided, final Configuration target) {
final DependencyHandler deps = this.project.getDependencies();

final Map<ModuleIdentifier, String> providedModuleVersions = new HashMap<>();
for (ResolvedArtifact artifact : provided.getResolvedConfiguration().getResolvedArtifacts()) {
final ComponentIdentifier id = artifact.getId().getComponentIdentifier();
if (id instanceof ModuleComponentIdentifier) {
final ModuleComponentIdentifier moduleId = (ModuleComponentIdentifier) id;
providedModuleVersions.put(moduleId.getModuleIdentifier(), moduleId.getVersion());
}
}

for (ResolvedArtifact artifact : source.getResolvedConfiguration().getResolvedArtifacts()) {
final ComponentIdentifier id = artifact.getId().getComponentIdentifier();
if (id instanceof ModuleComponentIdentifier) {
final ModuleComponentIdentifier moduleId = (ModuleComponentIdentifier) id;
final ModuleIdentifier module = moduleId.getModuleIdentifier();
final String version = moduleId.getVersion();

final String providedVersion = providedModuleVersions.get(module);
if (providedVersion == null) {
ModuleDependency dep = (ModuleDependency) deps.create(id.getDisplayName());
dep.setTransitive(false);
target.getDependencies().add(dep);
} else if (!providedVersion.equals(version)) {
this.logger.warn("Version mismatch for module {}. {} expects {} but {} has {}.", module, source.getName(), version, provided.getName(), providedVersion);
}
}

// projects are not copied because we cannot always recreate properly a project dependency from the resolved artefact
}
}

public void applyNamedDependencyOnOutput(final Project originProject, final SourceSet sourceAdding, final SourceSet targetSource, final Project implProject, final String dependencyConfigName) {
implProject.getLogger().lifecycle(
"[{}] Adding {}({}) to {}({}).{}",
Expand Down
33 changes: 26 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ val mixins by sourceSets.registering {
}
}

sourceSets.configureEach {
val sourceSet = this
val isMain = "main".equals(sourceSet.name)

val sourcesJarName: String = if (isMain) "sourcesJar" else (sourceSet.name + "SourcesJar")
tasks.register(sourcesJarName, Jar::class.java) {
group = "build"
val classifier = if (isMain) "sources" else (sourceSet.name + "-sources")
archiveClassifier.set(classifier)
from(sourceSet.allJava)
}
}

dependencies {
// api
api("org.spongepowered:spongeapi:$apiVersion")
Expand Down Expand Up @@ -404,11 +417,12 @@ allprojects {

tasks {
val jar by existing
val sourceJar by existing
val sourcesJar by existing
val mixinsJar by existing
val accessorsJar by existing
val launchJar by existing
val applaunchJar by existing

shadowJar {
mergeServiceFiles()
archiveClassifier.set("dev")
Expand All @@ -420,7 +434,7 @@ tasks {
from(commonManifest)
}
from(jar)
from(sourceJar)
from(sourcesJar)
from(mixinsJar)
from(accessorsJar)
from(launchJar)
Expand All @@ -430,20 +444,25 @@ tasks {
}
}
}

publishing {
publications {
register("sponge", MavenPublication::class) {
from(components["java"])
artifact(tasks["sourcesJar"])

artifact(tasks["sourceJar"])
artifact(tasks["mixinsJar"])
artifact(tasks["mixinsSourcesJar"])

artifact(tasks["accessorsJar"])
artifact(tasks["accessorsSourcesJar"])

artifact(tasks["launchJar"])
artifact(tasks["launchSourcesJar"])

artifact(tasks["applaunchJar"])
artifact(tasks["applaunchSourceJar"])
artifact(tasks["launchSourceJar"])
artifact(tasks["mixinsSourceJar"])
artifact(tasks["accessorsSourceJar"])
artifact(tasks["applaunchSourcesJar"])

pom {
artifactId = project.name.lowercase()
this.name.set(project.name)
Expand Down
Loading

0 comments on commit d035468

Please sign in to comment.