org.gradle.plugins.ide.idea.model.internal.IdeaDependenciesOptimizer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-api Show documentation
Show all versions of gradle-api Show documentation
Gradle 6.9.1 API redistribution.
/*
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.plugins.ide.idea.model.internal;
import com.google.common.collect.Multimap;
import com.google.common.collect.MultimapBuilder;
import org.gradle.plugins.ide.idea.model.Dependency;
import org.gradle.plugins.ide.idea.model.ModuleDependency;
import org.gradle.plugins.ide.idea.model.SingleEntryModuleLibrary;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
/**
* Minimizes a set of IDEA dependencies based on knowledge about how IDEA handles compilation and runtime of main and test classes:
*
*
* - COMPILE dependencies are visible everywhere.
* - PROVIDED dependencies are visible both when compiling main and test code as well as when running tests (but not when running main).
* - RUNTIME dependencies are visible when running main and test code.
* - TEST dependencies are visible when compiling and running tests.
*
*
* This means we can do the following simplifications:
*
*
* - If a dependency is in COMPILE, we can remove it everywhere else.
* - If a dependency is PROVIDED, we don't need it in TEST.
* - If a dependency is in RUNTIME and PROVIDED, we can hoist it up to COMPILE.
*
*
* This results is much closer to what a user would do by hand. Having less dependencies also makes IntelliJ faster.
*/
class IdeaDependenciesOptimizer {
public void optimizeDeps(Collection deps) {
Multimap
© 2015 - 2025 Weber Informatics LLC | Privacy Policy