use of org.gradle.plugins.ide.idea.model.IdeaModule in project gradle by gradle.
the class IdeaPlugin method visitAllImlArtifactsInComposite.
private void visitAllImlArtifactsInComposite(ProjectInternal project, IdeaProject ideaProject, TaskDependencyResolveContext context) {
ProjectComponentIdentifier thisProjectId = projectPathRegistry.stateFor(project).getComponentIdentifier();
for (IdeArtifactRegistry.Reference<IdeaModuleMetadata> reference : artifactRegistry.getIdeProjects(IdeaModuleMetadata.class)) {
BuildIdentifier otherBuildId = reference.getOwningProject().getBuild();
if (thisProjectId.getBuild().equals(otherBuildId)) {
// IDEA Module for project in current build: don't include any module that has been excluded from project
boolean found = false;
for (IdeaModule ideaModule : ideaProject.getModules()) {
if (reference.get().getFile().equals(ideaModule.getOutputFile())) {
found = true;
break;
}
}
if (!found) {
continue;
}
}
reference.visitDependencies(context);
}
}
use of org.gradle.plugins.ide.idea.model.IdeaModule in project gradle by gradle.
the class IdeaScalaConfigurer method resolveScalaCompilerLibraries.
private static Map<String, ProjectLibrary> resolveScalaCompilerLibraries(Collection<Project> scalaProjects, final boolean useScalaSdk) {
Map<String, ProjectLibrary> scalaCompilerLibraries = Maps.newLinkedHashMap();
for (final Project scalaProject : scalaProjects) {
final IdeaModule ideaModule = scalaProject.getExtensions().getByType(IdeaModel.class).getModule();
final Iterable<File> files = getIdeaModuleLibraryDependenciesAsFiles(ideaModule);
ProjectLibrary library = ((ProjectInternal) scalaProject).getOwner().fromMutableState(p -> createScalaSdkLibrary(scalaProject, files, useScalaSdk, ideaModule));
if (library != null) {
ProjectLibrary duplicate = Iterables.find(scalaCompilerLibraries.values(), Predicates.equalTo(library), null);
scalaCompilerLibraries.put(scalaProject.getPath(), duplicate == null ? library : duplicate);
}
}
return scalaCompilerLibraries;
}
use of org.gradle.plugins.ide.idea.model.IdeaModule in project curiostack by curioswitch.
the class CuriostackRootPlugin method setupJavaProject.
private static void setupJavaProject(Project project, Map<String, CheckSeverity> errorProneChecks) {
setupRepositories(project);
PluginContainer plugins = project.getPlugins();
plugins.apply(ErrorPronePlugin.class);
plugins.apply(IdeaPlugin.class);
plugins.apply(NullAwayPlugin.class);
plugins.apply(VersionsPlugin.class);
var java = project.getExtensions().getByType(JavaPluginExtension.class);
java.withJavadocJar();
java.withSourcesJar();
// Manage all dependencies by adding the bom as a platform.
Object bomDependency = isCuriostack(project) ? project.getDependencies().project(ImmutableMap.of("path", ":tools:curiostack-bom")) : "org.curioswitch.curiostack:curiostack-bom:" + ToolDependencies.getBomVersion(project);
var platformDependency = project.getDependencies().platform(bomDependency);
// Needs to be in afterEvaluate since there is no way to guarantee isCanBeResolved, etc
// are set otherwise.
project.getConfigurations().configureEach(configuration -> {
if (configuration instanceof DeprecatableConfiguration) {
if (((DeprecatableConfiguration) configuration).getDeclarationAlternatives() != null) {
return;
}
}
if (!configuration.getName().endsWith("Classpath") && !UNMANAGED_CONFIGURATIONS.contains(configuration.getName())) {
project.getDependencies().add(configuration.getName(), platformDependency);
}
});
project.afterEvaluate(unused -> {
plugins.withType(MavenPublishPlugin.class, unused2 -> {
var publishing = project.getExtensions().getByType(PublishingExtension.class);
publishing.getPublications().configureEach(publication -> {
if (!(publication instanceof MavenPublication)) {
return;
}
var mavenPublication = (MavenPublication) publication;
mavenPublication.versionMapping(mapping -> mapping.allVariants(VariantVersionMappingStrategy::fromResolutionResult));
mavenPublication.getPom().withXml(xml -> {
var root = xml.asNode();
findChild(root, "dependencyManagement").ifPresent(root::remove);
});
});
});
});
project.getTasks().withType(JavaCompile.class).configureEach(task -> {
task.getOptions().setIncremental(true);
ErrorProneOptions errorProne = ((ExtensionAware) task.getOptions()).getExtensions().findByType(ErrorProneOptions.class);
if (errorProne != null) {
errorProne.getDisableWarningsInGeneratedCode().set(true);
errorProne.getIgnoreUnknownCheckNames().set(true);
errorProne.getExcludedPaths().set("(.*/build/.*|.*/gen-src/.*)");
errorProne.getChecks().set(errorProneChecks);
var nullaway = ((ExtensionAware) errorProne).getExtensions().getByType(NullAwayOptions.class);
nullaway.getSeverity().set(WARN);
nullaway.getExcludedFieldAnnotations().addAll(MonotonicNonNull.class.getCanonicalName(), "org.mockito.Mock");
}
});
JavaPluginConvention javaPlugin = project.getConvention().getPlugin(JavaPluginConvention.class);
javaPlugin.setSourceCompatibility(JavaVersion.VERSION_16);
javaPlugin.setTargetCompatibility(JavaVersion.VERSION_16);
// Even for libraries that set source version to 8/11 for compatibility with older runtimes,
// we always use 15 for tests.
var testSourceSet = javaPlugin.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME);
project.getConfigurations().getByName(testSourceSet.getCompileClasspathConfigurationName()).getAttributes().attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 16);
project.getConfigurations().getByName(testSourceSet.getRuntimeClasspathConfigurationName()).getAttributes().attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 16);
project.getTasks().withType(Test.class).named("test").configure(test -> {
if (project.getRootProject().hasProperty("updateSnapshots")) {
test.jvmArgs(ImmutableList.of("-Dorg.curioswitch.testing.updateSnapshots=true"));
}
test.useJUnitPlatform(platform -> platform.includeEngines("junit-jupiter", "junit-vintage"));
test.testLogging(logging -> {
logging.setShowStandardStreams(true);
logging.setExceptionFormat(TestExceptionFormat.FULL);
});
});
// While Gradle attempts to generate a unique module name automatically,
// it doesn't seem to always work properly, so we just always use unique
// module names.
project.getPlugins().withType(IdeaPlugin.class, plugin -> {
IdeaModule module = plugin.getModel().getModule();
String moduleName = project.getName();
Project ancestor = project.getParent();
while (ancestor != null && ancestor != project.getRootProject()) {
moduleName = ancestor.getName() + "-" + moduleName;
ancestor = ancestor.getParent();
}
module.setName(moduleName);
project.getTasks().named("cleanIdea").configure(t -> t.doLast(unused -> project.file(project.getName() + ".iml").delete()));
});
// Pretty much all java code needs at least the Generated annotation.
project.getDependencies().add(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, "jakarta.annotation:jakarta.annotation-api");
project.getDependencies().add(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME, "org.checkerframework:checker-qual");
project.getDependencies().add(ErrorPronePlugin.CONFIGURATION_NAME, "com.google.errorprone:error_prone_core");
project.getDependencies().add(ErrorPronePlugin.CONFIGURATION_NAME, "com.uber.nullaway:nullaway");
project.getDependencies().add(ErrorPronePlugin.CONFIGURATION_NAME, "com.google.auto.value:auto-value-annotations");
project.afterEvaluate(CuriostackRootPlugin::addStandardJavaTestDependencies);
project.getConfigurations().all(configuration -> {
configuration.resolutionStrategy(ResolutionStrategy::preferProjectModules);
configuration.exclude(ImmutableMap.of("group", "com.google.guava", "module", "guava-jdk5"));
});
var javadoc = project.getTasks().withType(Javadoc.class).named("javadoc");
javadoc.configure(t -> {
CoreJavadocOptions options = (CoreJavadocOptions) t.getOptions();
options.quiet();
options.addBooleanOption("Xdoclint:all,-missing", true);
});
project.getTasks().register("resolveDependencies", resolveDependencies -> resolveDependencies.doLast(unused -> {
project.getConfigurations().all(configuration -> {
if (configuration.isCanBeResolved()) {
configuration.resolve();
}
});
}));
project.getPlugins().withType(JMHPlugin.class, unused -> {
JMHPluginExtension jmh = project.getExtensions().getByType(JMHPluginExtension.class);
// Benchmarks are usually very small and converge quickly. If this stops being the
// case
// these numbers can be adjusted.
jmh.setFork(2);
jmh.setIterations(5);
jmh.setProfilers(ImmutableList.of("hs_comp"));
jmh.setJmhVersion("1.19");
Object jmhRegex = project.getRootProject().findProperty("jmhRegex");
if (jmhRegex != null) {
jmh.setInclude((String) jmhRegex);
}
});
project.getPlugins().withType(JooqPlugin.class, unused -> project.getTasks().withType(JooqTask.class).configureEach(t -> {
for (String dependency : ImmutableList.of("javax.activation:activation", "mysql:mysql-connector-java", // Not sure why this isn't automatically added.
"com.google.guava:guava", "com.google.cloud.sql:mysql-socket-factory")) {
project.getDependencies().add("jooqRuntime", dependency);
}
}));
// It is very common to want to pass in command line system properties to the binary, so just
// always forward properties. It won't affect production since no one runs binaries via Gradle
// in production.
project.getTasks().withType(JavaExec.class).configureEach(task -> System.getProperties().entrySet().stream().filter(entry -> !((String) entry.getKey()).startsWith("java.")).forEach(entry -> task.systemProperty((String) entry.getKey(), entry.getValue())));
}
use of org.gradle.plugins.ide.idea.model.IdeaModule in project rest.li by linkedin.
the class PegasusPlugin method addGeneratedDir.
private static void addGeneratedDir(Project project, SourceSet sourceSet, Collection<Configuration> configurations) {
project.getPlugins().withType(IdeaPlugin.class, ideaPlugin -> {
IdeaModule ideaModule = ideaPlugin.getModel().getModule();
// stupid if block needed because of stupid assignment required to update source dirs
if (isTestSourceSet(sourceSet)) {
Set<File> sourceDirs = ideaModule.getTestSourceDirs();
sourceDirs.addAll(sourceSet.getJava().getSrcDirs());
// this is stupid but assignment is required
ideaModule.setTestSourceDirs(sourceDirs);
if (debug) {
System.out.println("Added " + sourceSet.getJava().getSrcDirs() + " to IdeaModule testSourceDirs " + ideaModule.getTestSourceDirs());
}
} else {
Set<File> sourceDirs = ideaModule.getSourceDirs();
sourceDirs.addAll(sourceSet.getJava().getSrcDirs());
// this is stupid but assignment is required
ideaModule.setSourceDirs(sourceDirs);
if (debug) {
System.out.println("Added " + sourceSet.getJava().getSrcDirs() + " to IdeaModule sourceDirs " + ideaModule.getSourceDirs());
}
}
Collection<Configuration> compilePlus = ideaModule.getScopes().get("COMPILE").get("plus");
compilePlus.addAll(configurations);
ideaModule.getScopes().get("COMPILE").put("plus", compilePlus);
});
}
Aggregations