Code Monkey home page Code Monkey logo

groovy's Introduction

@[TOC]





一、创建 Android Studio 工程



在 Android Studio 欢迎界面 , 选择 " Create New Project " 创建新的 Android 应用 ; 在这里插入图片描述

默认创建 Module 即可 , 应用的 Module 不能作为 Groovy 开发的工程 , 这里随意即可 , Groovy 开发工程需要额外创建 Java 依赖库 Module , 然后基于 Java 依赖库 Module 进行改造 ;

在这里插入图片描述

设置工程名称 , 然后点击 " Finish " 完成设置 ; 在这里插入图片描述

新创建的 Android 工程是一个空白工程 ;

在这里插入图片描述





二、创建 Java or Kotlin Library 类型的 Module



选择 " 菜单栏 / File / New / New Module ... " 选项 , 在本工程下创建 Module 工程 ;

在这里插入图片描述

选择创建 " Java or Kotlin Library " 的 Module ;

在这里插入图片描述

创建完后的依赖库 Module ;

在这里插入图片描述





三、改造 Java or Kotlin Library 类型的 Module



原来的 build.gradle 配置 :

plugins {
    id 'java-library'
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_7
    targetCompatibility = JavaVersion.VERSION_1_7
}

配置 Groovy 插件 : 在 plugins 中 , 配置

id 'groovy'

应用 Groovy 插件 ;


添加依赖 :

dependencies {
    implementation localGroovy()
}

配置完成的支持 Groovy 的 build.gradle :

plugins {
    id 'java-library'
    id 'groovy'
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_7
    targetCompatibility = JavaVersion.VERSION_1_7
}

dependencies {
    implementation localGroovy()
}

配置完毕后 , 编译该 Module 项目 , 编译成功 ;

在这里插入图片描述





四、编写 Groovy 代码文件并运行



右键点击该 Module 的 main 目录 , 选择 " New / Directory " 选项 ,

在这里插入图片描述

可以看到可以创建 groovy 目录 ;

在这里插入图片描述

右键点击 Groovy\groovy\src\main\groovy 目录 , 在弹出的菜单中选择 " New / File " 选项 ,

在这里插入图片描述

创建 Test.groovy 代码文件 ;

在这里插入图片描述

编辑 Test.groovy 代码 :

class Test {
    // Groovy 中的 main 函数
    def static main(def args) {
        // 在 Groovy 中可以使用 Java 语法
        System.out.println("Hello Groovy !!!")
    }
}

点击 main 函数左侧的运行按钮 , 运行该程序 , 运行结果如下 :

在这里插入图片描述

groovy's People

Contributors

han1202012 avatar

Watchers

 avatar

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.