0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Gradle ソース解析

0
Last updated at Posted at 2017-09-17

Gradle ソース解析

Gradleが内部的にどのように構成されているか確認するためにソースコードリーディングしています。
その際のメモです。バージョンは 4.1.0。

From https://github.com/gradle/gradle (tag: v4.1.0)

task

leftShift ( << ) でのタスク定義は非推奨となり v5.0 で削除予定

repositories

拡張プロパティ、プロジェクトプロパティ

    private static class CachingPropertyApplicator {
        private final Map<Pair<String, ? extends Class<?>>, PropertyMutator> mutators = Maps.newHashMap();
        private Class<? extends Project> projectClazz;

        void configureProperty(Project project, String name, Object value) {
            Class<? extends Project> clazz = project.getClass();
            if (clazz != projectClazz) {
                mutators.clear();
                projectClazz = clazz;
            }
            Class<?> valueType = value == null ? null : value.getClass();
            Pair<String, ? extends Class<?>> key = Pair.of(name, valueType);
            PropertyMutator propertyMutator = mutators.get(key);
            if (propertyMutator != null) {
                propertyMutator.setValue(project, value);
            } else {
                if (!mutators.containsKey(key)) {
                    propertyMutator = JavaReflectionUtil.writeablePropertyIfExists(clazz, name, valueType);
                    mutators.put(key, propertyMutator);
                    if (propertyMutator != null) {
                        propertyMutator.setValue(project, value);
                        return;
                    }
                }
                ExtraPropertiesExtension extraProperties = project.getExtensions().getExtraProperties();
                extraProperties.set(name, value);
            }
        }
    }

Configurations

なぜ configurations スコープに記述するだけでコンフィグレーションが生成される?

↓ DefaultConfiguration が生成される

org/gradle/api/internal/artifacts/configurations/DefaultConfiguration.

↓ dependencies スコープ側の delegate で動的にメソッド追加される

JavaPlugin

MavenPlugin

内部情報確認

repositories

build.gradle
def closure = {
  mavenCentral()
}

this.repositories(closure)
this.repositories.each { println it instanceof org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository }
//-> true
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?