How does the Gradle project support mixed use of Java and Scala?

Source: Internet
Author: User

I. Directory structure

Second, build.gradle configuration

Group ' Yjmyzz '
Version ' 1.0-snapshot '
Apply plugin: ' java '
Apply plugin: ' Scala '
Apply plugin: ' Application '/optional (can automatically generate shell startup scripts)
Mainclassname = ' Appdemo '//optional (with upstream application plugin)

Here's the key (mapping Java and Scala's source code directory all to Scala,
So Gradle Compilescala can compile both Java and Scala source code at the same time.
sourcesets {
Main {
Scala {
Srcdirs = [' Src/main/scala ', ' Src/main/java ']
}
java {
Srcdirs = []
}
}

Test {
Scala {
Srcdirs = [' Src/test/scala ', ' Src/test/java ']
}
java {
Srcdirs = []
}
}
}

Optional (Gradle Cdirs can be used to generate the SRC directory for Scala and Java at Project initialization)
Task "Createdirs" << {
Sourcesets*.scala.srcdirs*.each {it.mkdirs ()}
Sourcesets*.java.srcdirs*.each {it.mkdirs ()}
Sourcesets*.resources.srcdirs*.each {it.mkdirs ()}
}

repositories {
Mavenlocal ()
Maven {URL ' http://maven.aliyun.com/nexus/content/repositories/central/'}
Mavencentral ()
}

dependencies {
Compile "org.scala-lang:scala-library:2.11.7"
Compile "org.scala-lang:scala-compiler:2.11.7"
Compile "org.scala-lang:scala-reflect:2.11.7"
Testcompile "junit:junit:4.11"
}

Optionally, if you want the generated jar to run directly, it is recommended to add
Jar {
Manifest {
Attributes ' Main-class ': ' Appdemo '
}
}

This will do the following:

Create initial directory: Gradle cdirs (Note: This is abbreviated, exactly the same as Gradle Createdirs)

Compilation: Gradle Compilescala

Build jar Package: Gradle jar

To build a running package with a startup script: Gradle installdist

How does the Gradle project support mixed use of Java and Scala?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.