Search in sources :

Example 61 with Configuration

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

the class DownloadingScalaToolChain method select.

@Override
public ToolProvider select(ScalaPlatform targetPlatform) {
    try {
        Configuration scalaClasspath = resolveDependency("org.scala-lang:scala-compiler:" + targetPlatform.getScalaVersion());
        Configuration zincClasspath = resolveDependency("com.typesafe.zinc:zinc:" + DefaultScalaToolProvider.DEFAULT_ZINC_VERSION);
        Set<File> resolvedScalaClasspath = scalaClasspath.resolve();
        Set<File> resolvedZincClasspath = zincClasspath.resolve();
        return new DefaultScalaToolProvider(gradleUserHomeDir, rootProjectDir, workerDaemonFactory, resolvedScalaClasspath, resolvedZincClasspath);
    } catch (ResolveException resolveException) {
        return new NotFoundScalaToolProvider(resolveException);
    }
}
Also used : ResolveException(org.gradle.api.artifacts.ResolveException) Configuration(org.gradle.api.artifacts.Configuration) File(java.io.File)

Example 62 with Configuration

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

the class TDependencyManager method collectArtifacts.

/**
     * Collects the resolved artifacts and returns a configuration which contains them. If the
     * configuration has unresolved dependencies we check that we have the latest version of the
     * Google repository and the Android Support repository and we install them if not. After this,
     * the resolution is retried with a fresh copy of the configuration, that will contain the newly
     * updated repositories. If this passes, we return the correct configuration and we fill the
     * artifacts map.
     *
     * @param configuration the configuration from which we get the artifacts
     * @param artifacts     the map of artifacts that are being collected
     * @return a valid configuration that has only resolved dependencies.
     */
private Configuration collectArtifacts(Configuration configuration, Map<ModuleVersionIdentifier, List<ResolvedArtifact>> artifacts) {
    Set<ResolvedArtifact> allArtifacts;
    // Make a copy because Gradle keeps a per configuration state of resolution that we
    // need to reset.
    Configuration configurationCopy = configuration.copyRecursive();
    Set<UnresolvedDependency> unresolvedDependencies = configuration.getResolvedConfiguration().getLenientConfiguration().getUnresolvedModuleDependencies();
    if (unresolvedDependencies.isEmpty()) {
        allArtifacts = configuration.getResolvedConfiguration().getResolvedArtifacts();
    } else {
        if (!repositoriesUpdated && sdkLibData.useSdkDownload()) {
            List<String> repositoryPaths = new ArrayList<>();
            for (UnresolvedDependency dependency : unresolvedDependencies) {
                if (isGoogleOwnedDependency(dependency.getSelector())) {
                    repositoryPaths.add(getRepositoryPath(dependency.getSelector()));
                }
            }
            sdkLibData.setNeedsCacheReset(sdkHandler.checkResetCache());
            List<File> updatedRepositories = sdkHandler.getSdkLoader().updateRepositories(repositoryPaths, sdkLibData, logger);
            // resolution result.
            for (File updatedRepository : updatedRepositories) {
                project.getRepositories().maven(newRepo -> {
                    newRepo.setName("Updated " + updatedRepository.getPath());
                    newRepo.setUrl(updatedRepository.toURI());
                    newRepo.artifactUrls(project.getRootProject().file("sdk-manager"));
                });
            }
            repositoriesUpdated = true;
        }
        if (extraModelInfo.getMode() != STANDARD) {
            allArtifacts = configurationCopy.getResolvedConfiguration().getLenientConfiguration().getArtifacts(Specs.satisfyAll());
        } else {
            allArtifacts = configurationCopy.getResolvedConfiguration().getResolvedArtifacts();
        }
        // Modify the configuration to the one that passed.
        configuration = configurationCopy;
    }
    for (ResolvedArtifact artifact : allArtifacts) {
        ModuleVersionIdentifier id = artifact.getModuleVersion().getId();
        List<ResolvedArtifact> moduleArtifacts = artifacts.get(id);
        if (moduleArtifacts == null) {
            moduleArtifacts = Lists.newArrayList();
            artifacts.put(id, moduleArtifacts);
        }
        if (!moduleArtifacts.contains(artifact)) {
            moduleArtifacts.add(artifact);
        }
    }
    return configuration;
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) Configuration(org.gradle.api.artifacts.Configuration) UnresolvedDependency(org.gradle.api.artifacts.UnresolvedDependency) ArrayList(java.util.ArrayList) File(java.io.File)

Example 63 with Configuration

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

the class TDependencyManager method addDependsOnTaskInOtherProjects.

/**
     * Adds a dependency on tasks with the specified name in other projects.  The other projects
     * are determined from project lib dependencies using the specified configuration name.
     * These may be projects this project depends on or projects that depend on this project
     * based on the useDependOn argument.
     *
     * @param task                 Task to add dependencies to
     * @param useDependedOn        if true, add tasks from projects this project depends on, otherwise
     *                             use projects that depend on this one.
     * @param otherProjectTaskName name of task in other projects
     * @param configurationName    name of configuration to use to find the other projects
     */
private static void addDependsOnTaskInOtherProjects(final Task task, boolean useDependedOn, String otherProjectTaskName, String configurationName) {
    Project project = task.getProject();
    final Configuration configuration = project.getConfigurations().getByName(configurationName);
    task.dependsOn(configuration.getTaskDependencyFromProjectDependency(useDependedOn, otherProjectTaskName));
}
Also used : Project(org.gradle.api.Project) AndroidProject(com.android.builder.model.AndroidProject) Configuration(org.gradle.api.artifacts.Configuration)

Example 64 with Configuration

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

the class PrepareAPTask method generate.

/**
     * 生成so的目录
     */
@TaskAction
void generate() {
    Project project = getProject();
    File apBaseFile = null;
    if (null != apContext.getApFile() && apContext.getApFile().exists()) {
        apBaseFile = apContext.getApFile();
    } else if (StringUtils.isNotBlank(apContext.getApDependency())) {
        Dependency dependency = project.getDependencies().create(apContext.getApDependency());
        Configuration configuration = project.getConfigurations().detachedConfiguration(dependency);
        configuration.setTransitive(false);
        for (File file : configuration.getFiles()) {
            if (file.getName().endsWith(".ap")) {
                apBaseFile = file;
                break;
            }
        }
    }
    if (null != apBaseFile && apBaseFile.exists()) {
        File explodedDir = project.file(project.getBuildDir().getAbsolutePath() + "/" + FD_INTERMEDIATES + "/exploded-ap" + "/");
        ZipUtils.unzip(apBaseFile, explodedDir.getAbsolutePath());
        apContext.setApExploredFolder(explodedDir);
        apContext.setBaseApk(new File(explodedDir, "android.apk"));
    }
}
Also used : Project(org.gradle.api.Project) Configuration(org.gradle.api.artifacts.Configuration) Dependency(org.gradle.api.artifacts.Dependency) File(java.io.File) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 65 with Configuration

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

the class ProjectLibraries method getLibraries.

private Set<GradleLibrary> getLibraries(String configurationName, LibraryScope scope) {
    Configuration configuration = (configurationName == null ? null : this.project.getConfigurations().findByName(configurationName));
    if (configuration == null) {
        return null;
    }
    Set<GradleLibrary> libraries = new LinkedHashSet<>();
    for (ResolvedArtifact artifact : configuration.getResolvedConfiguration().getResolvedArtifacts()) {
        libraries.add(new ResolvedArtifactLibrary(artifact, scope));
    }
    libraries.addAll(getLibrariesForFileDependencies(configuration, scope));
    return libraries;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) Configuration(org.gradle.api.artifacts.Configuration)

Aggregations

Configuration (org.gradle.api.artifacts.Configuration)65 File (java.io.File)8 Project (org.gradle.api.Project)8 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)8 Dependency (org.gradle.api.artifacts.Dependency)7 DependencySet (org.gradle.api.artifacts.DependencySet)7 Callable (java.util.concurrent.Callable)6 ConventionMapping (org.gradle.api.internal.ConventionMapping)5 IConventionAware (org.gradle.api.internal.IConventionAware)5 LinkedHashSet (java.util.LinkedHashSet)4 ResolvedConfiguration (org.gradle.api.artifacts.ResolvedConfiguration)4 ResolvedProjectConfiguration (org.gradle.api.internal.artifacts.ivyservice.resolveengine.projectresult.ResolvedProjectConfiguration)4 JavaScriptExtension (org.gradle.plugins.javascript.base.JavaScriptExtension)4 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)3 PublishArtifact (org.gradle.api.artifacts.PublishArtifact)3 DependencyResult (org.gradle.api.artifacts.result.DependencyResult)3 FileCollection (org.gradle.api.file.FileCollection)3 ArchivePublishArtifact (org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact)3 DefaultArtifactPublicationSet (org.gradle.api.internal.plugins.DefaultArtifactPublicationSet)3 DslObject (org.gradle.api.internal.plugins.DslObject)3