Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detached configuration dependency report #542

Open
TWiStErRob opened this issue Jul 10, 2023 · 0 comments
Open

Detached configuration dependency report #542

TWiStErRob opened this issue Jul 10, 2023 · 0 comments
Labels
a:feature new feature, improvement or request on:gradle issue related to Gradle

Comments

@TWiStErRob
Copy link
Owner

@UntrackedTask(because = "Console output only.")
abstract class DetachedConfigurationReportTask extends AbstractDependencyReportTask {

	@Input
	abstract ListProperty<Configuration> getDetachedConfigurations()

	@Override
	ConfigurationContainer getTaskConfigurations() {
		def configurations = new ExistingConfigurationContainer()
		configurations.addAll(detachedConfigurations.get())
		return configurations
	}
}
ExistingConfigurationContainer
@SuppressWarnings('GrUnnecessaryPublicModifier')
public class ExistingConfigurationContainer
		extends org.gradle.api.internal.AbstractNamedDomainObjectContainer<Configuration>
		implements ConfigurationContainer {

	public ExistingConfigurationContainer() {
		super(Configuration.class, null, { name }, null)
	}
	@Override
	public Configuration detachedConfiguration(Dependency... dependencies) {
		throw new UnsupportedOperationException("$this cannot create a detached configuration.")
	}
	@Override
	protected Configuration doCreate(String name) {
		throw new UnsupportedOperationException("$this cannot create a configuration named $name.")
	}
	@Override
	public Configuration getAt(String name) {
		return (Configuration)super.getAt(name)
	}
	@Override
	public Configuration findByName(String name) {
		return (Configuration)super.findByName(name)
	}
	@Override
	public Configuration getByName(String name) {
		return (Configuration)super.getByName(name)
	}
	@Override
	public Configuration getByName(String name, Closure configureClosure)
			throws UnknownDomainObjectException {
		return (Configuration)super.getByName(name, configureClosure)
	}
	@Override
	public Configuration getByName(String name, Action<? super Configuration> configureAction)
			throws UnknownDomainObjectException {
		return (Configuration)super.getByName(name, configureAction)
	}
}

Motivation: wanted to see what was called lintClassPath in old AGPs. In AGP 8 it's a detached configuration, hidden away:

afterEvaluate {
	tasks.register("detached", DetachedConfigurationReportTask) {
		detachedConfigurations.add(
			tasks.named("lintAnalyzeDebug")
			     .map { com.android.build.gradle.internal.lint.AndroidLintAnalysisTask task ->
				     // Hack com.android.build.gradle.internal.lint.LintFromMaven's detached config.
				     println(task.lintTool.classpath.class)
				     println(task.lintTool.classpath.sourceCollections)
				     def c = task.lintTool.classpath.sourceCollections.first()
				     println(c)
				     c
			     }
			     // If this is not done eagerly while configuring,
			     // and the lintTool.classpath gets resolved,
			     // The sourceCollections will return Files instead of the originating Configuration.
			     // See DefaultConfigurableFileCollection#calculateFinalizedValue for why this happens (value = ...).
			     .get()
		)
	}
@TWiStErRob TWiStErRob added a:feature new feature, improvement or request on:gradle issue related to Gradle labels Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:feature new feature, improvement or request on:gradle issue related to Gradle
Projects
None yet
Development

No branches or pull requests

1 participant