Skip to content

Commit

Permalink
Fallback to implementation if api configurations do not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Johni0702 committed Jun 4, 2021
1 parent 339f49b commit 78aded6
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/main/java/net/minecraftforge/gradle/user/UserBasePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.gradle.api.Task;
import org.gradle.api.XmlProvider;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.ExternalModuleDependency;
import org.gradle.api.artifacts.ModuleVersionIdentifier;
Expand Down Expand Up @@ -517,22 +518,36 @@ protected void configureCompilation()
.plus(project.getConfigurations().getByName(CONFIG_MC))
.plus(project.getConfigurations().getByName(CONFIG_MC_DEPS)));

project.getConfigurations().getByName(JavaPlugin.API_CONFIGURATION_NAME).extendsFrom(project.getConfigurations().getByName(CONFIG_DC_RESOLVED));
project.getConfigurations().getByName(CONFIG_PROVIDED).extendsFrom(project.getConfigurations().getByName(CONFIG_DP_RESOLVED));
project.getConfigurations().getByName(api.getApiConfigurationName()).extendsFrom(project.getConfigurations().getByName(JavaPlugin.API_CONFIGURATION_NAME));
project.getConfigurations().getByName(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME).extendsFrom(project.getConfigurations().getByName(api.getApiConfigurationName()));
ConfigurationContainer cfgs = project.getConfigurations();
extendsFrom(cfgs.findByName(JavaPlugin.API_CONFIGURATION_NAME), cfgs.findByName(CONFIG_DC_RESOLVED));
extendsFrom(cfgs.findByName(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME), cfgs.findByName(CONFIG_DC_RESOLVED));
extendsFrom(cfgs.findByName(CONFIG_PROVIDED), cfgs.findByName(CONFIG_DP_RESOLVED));
extendsFrom(cfgs.findByName(api.getApiConfigurationName()), cfgs.findByName(JavaPlugin.API_CONFIGURATION_NAME));
extendsFrom(cfgs.findByName(api.getImplementationConfigurationName()), cfgs.findByName(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME));
extendsFrom(cfgs.findByName(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME), cfgs.findByName(api.getApiConfigurationName()));
extendsFrom(cfgs.findByName(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME), cfgs.findByName(api.getImplementationConfigurationName()));

Javadoc javadoc = (Javadoc) project.getTasks().getByName(JavaPlugin.JAVADOC_TASK_NAME);
javadoc.setClasspath(main.getOutput().plus(main.getCompileClasspath()));

// libs folder dependencies
project.getDependencies().add(JavaPlugin.API_CONFIGURATION_NAME, project.fileTree("libs"));
if (cfgs.findByName(JavaPlugin.API_CONFIGURATION_NAME) != null) {
project.getDependencies().add(JavaPlugin.API_CONFIGURATION_NAME, project.fileTree("libs"));
} else {
project.getDependencies().add(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, project.fileTree("libs"));
}

// set the compile target
javaConv.setSourceCompatibility("1.8");
javaConv.setTargetCompatibility("1.8");
}

private void extendsFrom(Configuration configuration, Configuration base) {
if (configuration != null && base != null) {
configuration.extendsFrom(base);
}
}

/**
* Creates and partially configures the source replacement tasks. The actual replacements must be configured afterEvaluate.
*/
Expand Down Expand Up @@ -645,8 +660,10 @@ public Boolean call(Object o)

protected final void doDevTimeDeobf()
{
final Task compileDummy = getDummyDep("api", delayedFile(DIR_DEOBF_DEPS + "/compileDummy.jar"), TASK_DD_COMPILE);
final Task providedDummy = getDummyDep("api", delayedFile(DIR_DEOBF_DEPS + "/providedDummy.jar"), TASK_DD_PROVIDED);
Configuration config = project.getConfigurations().findByName(JavaPlugin.API_CONFIGURATION_NAME);
String configName = config != null ? config.getName() : JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME;
final Task compileDummy = getDummyDep(configName, delayedFile(DIR_DEOBF_DEPS + "/compileDummy.jar"), TASK_DD_COMPILE);
final Task providedDummy = getDummyDep(configName, delayedFile(DIR_DEOBF_DEPS + "/providedDummy.jar"), TASK_DD_PROVIDED);

setupDevTimeDeobf(compileDummy, providedDummy);
}
Expand Down

0 comments on commit 78aded6

Please sign in to comment.