Giter VIP home page Giter VIP logo

project-replicator's Introduction

Gradle Project Replicator

This project contains a Gradle plugin and a small command-line app that allows replicating the structure of a given Gradle project.

This replicates the project's module structure, and for each project replicates the applied plugins, some of their configurations, and the dependencies (both internal and external). All the module names are anonymized.

How to use

See USAGE.md

todo list

See TODO.md

Versions

0.2 Add support for android.BuildFeatures.

0.1 Initial version.

Disclaimer

This is not an officially supported Google product.

License

Copyright 2020 The Android Open Source Project

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

    https://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.

project-replicator's People

Contributors

davidburstromspotify avatar ducrohet avatar gavra0 avatar jdochez avatar temennigru avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

project-replicator's Issues

xml parser skips files with DOCTYPE entries

> Task :my-module:gatherModuleInfo
e: Invalid xml file my-module/src/main/res/values/strings.xml
   line 4; column 10: DOCTYPE is disallowed when the feature "http://apache.org/xml/features/disallow-doctype-decl" set to true.
   <!DOCTYPE resources [
            ↑
Skipping file parsing

This does not terminate the process, it just skips the file.

I'm not sure what the reason is for disallowing DOCTYPE, but it is useful to add named entities for unusual characters. For example, we use it to define entity aliases like these that we can then use in our strings:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE resources [
    <!ENTITY ldquo  "&#8220;">
    <!ENTITY rdquo  "&#8221;">
    <!ENTITY lsquo  "&#8216;">
    <!ENTITY rsquo  "&#8217;">
    <!ENTITY hellip "&#8230;">
    <!ENTITY prime  "&#8242;">
    <!ENTITY Prime  "&#8243;">
    <!ENTITY bull   "&#8226;">
    <!ENTITY thinsp "&#8201;">
    <!ENTITY hairsp "&#8202;">
    ]>

Then later we can refer to these standard entity names in the strings:

<string name="string_name">One last thing&hellip;</string>

In this case, we prefer to use &hellip; here, because it is more meaningful for translators, and it is more grammatically correct. I.e., using vs .... It also translates differently for some languages - for example, some languages prefer a different type of ellipsis, like the midline () or vertical ellipsis ().

Inlining the unicode character can often be difficult for people reading the file to understand that it is a unicode character rather than its similar non-unicode counterpart (i.e., ' apostrophe vs right-single quotation or rsquo), which is why we use the &#<>; notation. And inlining that notation into the string, someone reading the file won't understand what that number represents unless they look it up.

So the workaround is using the named XML entity: it gives us the exact unicode representation, with a meaningful name, without compromising the character width which can have an impact on some older editors that aren't well equipped to handle multi-byte unicode characters.

Plugin requires Java 15

Kotlin 1.7.20
Android Gradle Plugin 7.3.1
Gradle 7.5.1

I have built the plugin to the local Maven repository and modified my project's main build.gradle.kts like this:

buildscript {
    repositories {
        mavenLocal()
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.gradle.replicator:project-replicator:0.2")
        classpath(libs.kotlin.pluginGradle)
        classpath(libs.android.pluginGradle)
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()

    apply {
        plugin("com.android.gradle.replicator.ProjectReplicatorPlugin")
    }

    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class) {
        kotlinOptions.jvmTarget = JavaVersion.VERSION_11.toString()
    }
}

However when syncing Gradle I get the following error:

> Could not determine the dependencies of null.
   > Could not resolve all task dependencies for configuration ':classpath'.
      > Could not resolve com.android.gradle.replicator:project-replicator:0.2.
        Required by:
            project :
         > No matching variant of com.android.gradle.replicator:project-replicator:0.2 was found. The consumer was configured to find a runtime of a library compatible with Java 11, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.5.1' but:
             - Variant 'apiElements' capability com.android.gradle.replicator:project-replicator:0.2 declares a library, packaged as a jar, and its dependencies declared externally:
                 - Incompatible because this component declares an API of a component compatible with Java 15 and the consumer needed a runtime of a component compatible with Java 11
                 - Other compatible attribute:
                     - Doesn't say anything about org.gradle.plugin.api-version (required '7.5.1')
             - Variant 'runtimeElements' capability com.android.gradle.replicator:project-replicator:0.2 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
                 - Incompatible because this component declares a component compatible with Java 15 and the consumer needed a component compatible with Java 11
                 - Other compatible attribute:
                     - Doesn't say anything about org.gradle.plugin.api-version (required '7.5.1')

Plugin cannot be applied as documented

Trying to apply the plugin as described in https://github.com/android/project-replicator/blob/master/docs/USAGE.md results in multiple build errors, at various times:

* What went wrong:
A problem occurred evaluating project ':host-api-demo'.
> KOTLIN_STAT_ENABLED_PROPERTY
* What went wrong:
A problem occurred configuring project ':host-api-demo'.
> com.android.builder.errors.EvalIssueException: compileSdkVersion is not specified. Please add it to build.gradle
* What went wrong:
A problem occurred evaluating project ':host-api-demo'.
> Could not initialize class org.jetbrains.kotlin.gradle.plugin.KotlinGradleBuildServices

These Android modules do have compileSdkVersion (or compileSdk using newer dsl). Some modules are not Android modules.

What worked for me was to move the buildscript/classpath entry from build.gradle into settings.gradle's pluginManagement block, add the plugin by id to settings.gradle's plugin{} block, add a resolutionStrategy (since there's no gradle plugin marker published) to resolve the plugin id, and then change the init.gradle's allprojects{apply} to apply by plugin id.

--- settings.gradle
+++ settings.gradle
@@ -48,0 +48,1 @@ pluginManagement {
+        id "com.android.gradle.project.replicator" version "0.2"
@@ -55,2 +56,5 @@ pluginManagement {
     resolutionStrategy {
         eachPlugin {
+            if (requested.id.id == "com.android.gradle.project.replicator") {
+                useModule("com.android.gradle.replicator:project-replicator:0.2")
+            }
@@ -69,0 +72,1 @@ plugins {
+    id "com.android.gradle.project.replicator" apply false
--- build.gradle
+++ build.gradle
@@ -27,0 +30,3 @@
+allprojects {
+    apply plugin: "com.android.gradle.project.replicator"
+}

This allowed :getStructure to complete successfully.

  • Gradle 8.0.2
  • AGP 7.4.2
  • 202 total modules count

Update documentation for Kotlin DSL

Hi!

This code in build.gradle.kts doesn't work:

plugins {
    kotlin("jvm") version "1.7.21"
}

buildscript {
    repositories {
        repositories {
            mavenLocal()
            jcenter()
        }
        dependencies {
            classpath("com.android.gradle.replicator:project-replicator:0.2")
        }
    }
}

allprojects {
    apply(plugin = "com.android.gradle.replicator.ProjectReplicatorPlugin") // Plugin with id 'com.android.gradle.replicator.ProjectReplicatorPlugin' not found.
}

What should I do to make it work?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.