Search in sources :

Example 41 with Dependency

use of org.gradle.api.artifacts.Dependency in project gradle by gradle.

the class DefaultConfigurationContainer method detachedConfiguration.

public ConfigurationInternal detachedConfiguration(Dependency... dependencies) {
    String name = DETACHED_CONFIGURATION_DEFAULT_NAME + detachedConfigurationDefaultNameCounter++;
    DetachedConfigurationsProvider detachedConfigurationsProvider = new DetachedConfigurationsProvider();
    DefaultConfiguration detachedConfiguration = instantiator.newInstance(DefaultConfiguration.class, context, name, detachedConfigurationsProvider, resolver, listenerManager, dependencyMetaDataProvider, resolutionStrategyFactory, projectAccessListener, projectFinder, fileCollectionFactory, buildOperationExecutor, instantiator, artifactNotationParser, capabilityNotationParser, attributesFactory, rootComponentMetadataBuilder.withConfigurationsProvider(detachedConfigurationsProvider));
    DomainObjectSet<Dependency> detachedDependencies = detachedConfiguration.getDependencies();
    for (Dependency dependency : dependencies) {
        detachedDependencies.add(dependency.copy());
    }
    detachedConfigurationsProvider.setTheOnlyConfiguration(detachedConfiguration);
    return detachedConfiguration;
}
Also used : Dependency(org.gradle.api.artifacts.Dependency)

Example 42 with Dependency

use of org.gradle.api.artifacts.Dependency in project shipkit by mockito.

the class CreateDependencyInfoFile method createDependencyInfoFile.

public void createDependencyInfoFile(CreateDependencyInfoFileTask task) {
    String result = "# Description" + NEWLINE + DESCRIPTION + NEWLINE + "# Dependencies";
    // sorting dependencies to assure that they are always in the same order
    // without depending on Gradle implementation
    SortedSet<String> dependencies = new TreeSet<>();
    for (Dependency dependency : task.getConfiguration().getAllDependencies()) {
        if (dependency instanceof ModuleDependency) {
            String dep = getDependencyWithArtifacts(task, (ModuleDependency) dependency);
            dependencies.add(dep);
        }
    }
    result += DEPENDENCY_INDENT + StringUtil.join(dependencies, DEPENDENCY_INDENT);
    IOUtil.writeFile(task.getOutputFile(), result.toString());
}
Also used : ModuleDependency(org.gradle.api.artifacts.ModuleDependency) TreeSet(java.util.TreeSet) Dependency(org.gradle.api.artifacts.Dependency) ModuleDependency(org.gradle.api.artifacts.ModuleDependency)

Example 43 with Dependency

use of org.gradle.api.artifacts.Dependency in project atlas by alibaba.

the class UpdatePomTask method getExtraMap.

private Map<String, DependencyExtraInfo> getExtraMap() {
    Map<String, DependencyExtraInfo> dependencyExtraInfoMap = new HashMap<>();
    DependencySet dependencies = project.getConfigurations().getByName("compile").getDependencies();
    dependencies.forEach(new Consumer<Dependency>() {

        @Override
        public void accept(Dependency dependency) {
            String group = dependency.getGroup();
            String name = dependency.getName();
            String scope = "compile";
            String type = "";
            if (dependency instanceof DefaultProjectDependency) {
                DefaultProjectDependency projectDependency = (DefaultProjectDependency) dependency;
                if (projectDependency.getDependencyProject().getPlugins().hasPlugin(LibraryPlugin.class)) {
                    type = "aar";
                }
            }
            dependencyExtraInfoMap.put(group + ":" + name, new DependencyExtraInfo(type, scope));
        }
    });
    return dependencyExtraInfoMap;
}
Also used : HashMap(java.util.HashMap) DefaultProjectDependency(org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency) DependencySet(org.gradle.api.artifacts.DependencySet) DefaultProjectDependency(org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency) Dependency(org.gradle.api.artifacts.Dependency) LibraryPlugin(com.android.build.gradle.LibraryPlugin)

Example 44 with Dependency

use of org.gradle.api.artifacts.Dependency in project atlas by alibaba.

the class PrepareAPTask method generate.

/**
 * Directory of so
 */
@TaskAction
void generate() throws IOException, DocumentException {
    Project project = getProject();
    File apBaseFile = null;
    File apFile = getApFile();
    if (null != apFile && apFile.exists()) {
        apBaseFile = apFile;
    } else {
        String apDependency = getApDependency();
        if (StringUtils.isNotBlank(apContext.getApDependency())) {
            Dependency dependency = project.getDependencies().create(apDependency);
            Configuration configuration = project.getConfigurations().detachedConfiguration(dependency);
            configuration.setTransitive(false);
            configuration.getResolutionStrategy().cacheChangingModulesFor(0, TimeUnit.MILLISECONDS);
            configuration.getResolutionStrategy().cacheDynamicVersionsFor(0, TimeUnit.MILLISECONDS);
            for (File file : configuration.getFiles()) {
                if (file.getName().endsWith(".ap")) {
                    apBaseFile = file;
                    break;
                }
            }
        }
    }
    if (null != apBaseFile && apBaseFile.exists()) {
        try {
            explodedDir = getExplodedDir();
            BetterZip.unzipDirectory(apBaseFile, explodedDir);
            apContext.setApExploredFolder(explodedDir);
            Set<String> awbBundles = getAwbBundles();
            if (awbBundles != null) {
                // Unzip the baseline Bundle
                for (String awbBundle : awbBundles) {
                    File awbFile = BetterZip.extractFile(new File(explodedDir, AP_INLINE_APK_FILENAME), "lib/armeabi/" + awbBundle, new File(explodedDir, AP_INLINE_AWB_EXTRACT_DIRECTORY));
                    File awbExplodedDir = new File(new File(explodedDir, AP_INLINE_AWB_EXPLODED_DIRECTORY), FilenameUtils.getBaseName(awbBundle));
                    BetterZip.unzipDirectory(awbFile, awbExplodedDir);
                    FileUtils.renameTo(new File(awbExplodedDir, FN_APK_CLASSES_DEX), new File(awbExplodedDir, "classes2.dex"));
                }
                // Preprocessing increment androidmanifest.xml
                ManifestFileUtils.updatePreProcessBaseManifestFile(FileUtils.join(explodedDir, "manifest-modify", ANDROID_MANIFEST_XML), new File(explodedDir, ANDROID_MANIFEST_XML));
            }
            if (explodedDir.listFiles().length == 0) {
                throw new RuntimeException("unzip ap exception, no files found");
            }
        } catch (Throwable e) {
            FileUtils.deleteIfExists(apBaseFile);
            throw new GradleException(e.getMessage(), e);
        }
    }
}
Also used : Project(org.gradle.api.Project) Configuration(org.gradle.api.artifacts.Configuration) GradleException(org.gradle.api.GradleException) Dependency(org.gradle.api.artifacts.Dependency) File(java.io.File) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)

Example 45 with Dependency

use of org.gradle.api.artifacts.Dependency in project spring-boot by spring-projects.

the class JavaConventions method configureDependencyManagement.

private void configureDependencyManagement(Project project) {
    ConfigurationContainer configurations = project.getConfigurations();
    Configuration dependencyManagement = configurations.create("dependencyManagement", (configuration) -> {
        configuration.setVisible(false);
        configuration.setCanBeConsumed(false);
        configuration.setCanBeResolved(false);
    });
    configurations.matching((configuration) -> configuration.getName().endsWith("Classpath") || JavaPlugin.ANNOTATION_PROCESSOR_CONFIGURATION_NAME.equals(configuration.getName())).all((configuration) -> configuration.extendsFrom(dependencyManagement));
    Dependency springBootParent = project.getDependencies().enforcedPlatform(project.getDependencies().project(Collections.singletonMap("path", ":spring-boot-project:spring-boot-parent")));
    dependencyManagement.getDependencies().add(springBootParent);
    project.getPlugins().withType(OptionalDependenciesPlugin.class, (optionalDependencies) -> configurations.getByName(OptionalDependenciesPlugin.OPTIONAL_CONFIGURATION_NAME).extendsFrom(dependencyManagement));
}
Also used : Arrays(java.util.Arrays) CheckFormat(io.spring.javaformat.gradle.tasks.CheckFormat) OptionalDependenciesPlugin(org.springframework.boot.build.optional.OptionalDependenciesPlugin) TestRetryTaskExtension(org.gradle.testretry.TestRetryTaskExtension) JavaPlugin(org.gradle.api.plugins.JavaPlugin) TestFailuresPlugin(org.springframework.boot.build.testing.TestFailuresPlugin) DependencySet(org.gradle.api.artifacts.DependencySet) SourceSet(org.gradle.api.tasks.SourceSet) Configuration(org.gradle.api.artifacts.Configuration) Javadoc(org.gradle.api.tasks.javadoc.Javadoc) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) Map(java.util.Map) Test(org.gradle.api.tasks.testing.Test) CheckstylePlugin(org.gradle.api.plugins.quality.CheckstylePlugin) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) Checkstyle(org.gradle.api.plugins.quality.Checkstyle) CheckClasspathForProhibitedDependencies(org.springframework.boot.build.classpath.CheckClasspathForProhibitedDependencies) Jar(org.gradle.api.tasks.bundling.Jar) Project(org.gradle.api.Project) Set(java.util.Set) Collectors(java.util.stream.Collectors) JavaVersion(org.gradle.api.JavaVersion) TestRetryPlugin(org.gradle.testretry.TestRetryPlugin) List(java.util.List) SpringJavaFormatPlugin(io.spring.javaformat.gradle.SpringJavaFormatPlugin) CoreJavadocOptions(org.gradle.external.javadoc.CoreJavadocOptions) TreeMap(java.util.TreeMap) Format(io.spring.javaformat.gradle.tasks.Format) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) CheckstyleExtension(org.gradle.api.plugins.quality.CheckstyleExtension) Collections(java.util.Collections) Dependency(org.gradle.api.artifacts.Dependency) ToolchainPlugin(org.springframework.boot.build.toolchain.ToolchainPlugin) StringUtils(org.springframework.util.StringUtils) Configuration(org.gradle.api.artifacts.Configuration) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) Dependency(org.gradle.api.artifacts.Dependency)

Aggregations

Dependency (org.gradle.api.artifacts.Dependency)58 Configuration (org.gradle.api.artifacts.Configuration)20 ProjectDependency (org.gradle.api.artifacts.ProjectDependency)16 File (java.io.File)13 Project (org.gradle.api.Project)13 ModuleDependency (org.gradle.api.artifacts.ModuleDependency)12 ExternalModuleDependency (org.gradle.api.artifacts.ExternalModuleDependency)8 MinimalExternalModuleDependency (org.gradle.api.artifacts.MinimalExternalModuleDependency)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 FileCollectionDependency (org.gradle.api.artifacts.FileCollectionDependency)6 Collectors (java.util.stream.Collectors)5 Inject (javax.inject.Inject)5 DependencySet (org.gradle.api.artifacts.DependencySet)5 ObjectFactory (org.gradle.api.model.ObjectFactory)5 TaskDependency (org.gradle.api.tasks.TaskDependency)5 EtaDependency (com.typelead.gradle.eta.api.EtaDependency)4 EtaProjectDependency (com.typelead.gradle.eta.api.EtaProjectDependency)4 Map (java.util.Map)4 Provider (org.gradle.api.provider.Provider)4