Gradle 之插件 gretty 入门

英文来源:  http://akhikhl.github.io/gretty-doc/Getting-started.html

 

在你的app应用的 "build.gradle" 中加入:

 

apply plugin: 'war'
apply from: 'https://raw.github.com/akhikhl/gretty/master/pluginScripts/gretty.plugin'

 大功告成! 现在你可以使用以下命令启动你的web-app;

 

 

gradle appRun

你也可以使用其他 Gretty tasks (Gretty 任务) 来运行和调试你的web-app 或者根据你的需求 configure Gretty  (配置Gretty).

又或者, 你可以从以下URL下载脚本并放置在项目文件夹下并这样把它包括进来:

https://raw.github.com/akhikhl/gretty/master/pluginScripts/gretty.plugin 

 

apply from: 'gretty.plugin'
 又或者轻松随意地把如下脚本加入你的 "build.gradle":

 

 

buildscript {
  repositories {
    jcenter()
    // enable this to use snapshot versions of Gretty:
    // maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local' }
  }

  dependencies {
    classpath 'org.akhikhl.gretty:gretty:+'
  }
}

repositories {
  jcenter()
  // enable this to use snapshot versions of Gretty:
  // maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local' }
}

apply plugin: 'org.akhikhl.gretty'
 

 使用gretty来运行jetty: gradle appRun

 

apply plugin: 'war'
apply from: 'https://raw.github.com/akhikhl/gretty/master/pluginScripts/gretty.plugin'
targetCompatibility = 1.8
version = "1.0"
ext {
    springVersion = "3.2.8.RELEASE"
}
repositories{
	mavenCentral()
}
[compileJava,compileTestJava,javadoc]*.options*.encoding = "gbk"
dependencies{
    compile "org.apache.struts:struts2-core:2.1.8.1"
    providedCompile "javax.servlet:javax.servlet-api:3.1.0"
    providedCompile "javax.servlet.jsp:jsp-api:2.2.1-b03"
    testCompile "junit:junit:4.11"
}
 

 

使用Gradle 官方jetty插件来运行jetty(目前仅支持到jetty6, 不支持 jetty7, 8, 9):  gradle jettyRunWar

apply plugin:"war"
apply plugin:"jetty"
targetCompatibility = 1.8
version = "1.0"
ext {
    springVersion = "3.2.8.RELEASE"
}
repositories{
	mavenCentral()
}
[compileJava,compileTestJava,javadoc]*.options*.encoding = "gbk"
dependencies{
    compile "org.apache.struts:struts2-core:2.1.8.1"
    providedCompile "javax.servlet:javax.servlet-api:3.1.0"
    providedCompile "javax.servlet.jsp:jsp-api:2.2.1-b03"
    testCompile "junit:junit:4.11"
}
jettyRun{
    webAppSourceDirectory file("$projectDir/src/main/webapp")
    httpPort 8080
    contextPath project.name
    scanIntervalSeconds 0
    reload "automatic"
}

 

使用Maven的命令来在jetty中运行web应用:  mvn jetty:run

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.lyq.action</groupId>
    <artifactId>e14_3</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>e14_3</name>

    <properties>
        <struts2.version>2.3.16.3</struts2.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>
            <version>${struts2.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-config-browser-plugin</artifactId>
            <version>${struts2.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-junit-plugin</artifactId>
            <version>${struts2.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.3</version>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.5</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>8.1.7.v20120910</version>
                <configuration>
                    <stopKey>CTRL+C</stopKey>
                    <stopPort>8999</stopPort>
                    <systemProperties>
                        <systemProperty>
                            <name>log4j.configuration</name>
                            <value>file:${basedir}/src/main/resources/log4j.properties</value>
                        </systemProperty>
                        <systemProperty>
                            <name>slf4j</name>
                            <value>false</value>
                        </systemProperty>
                    </systemProperties>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <webAppSourceDirectory>${basedir}/src/main/webapp/</webAppSourceDirectory>
                    <webAppConfig>
                        <contextPath>/e14_3</contextPath>
                        <descriptor>${basedir}/src/main/webapp/WEB-INF/web.xml</descriptor>
                    </webAppConfig>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>log4j</groupId>
                        <artifactId>log4j</artifactId>
                        <version>1.2.17</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>

 

 

注意
所有gretty的发布版本均在 jcenter 和 maven central. GroupId:  org.akhikhl.gretty.
注意
gretty的快照版本在jfrog artifactory
重要

如果你初学gretty遇到问题, 请先查看 troubleshooting 一节.

如果无效, 请提出一个问题在 Gretty issue tracker 或电邮 send an email 给 Gretty 开发人员.

你可能感兴趣的:(gradle)