JAVA EXAMPLE PROGRAMS

JAVA EXAMPLE PROGRAMS

Publish Your Article Here

How to create java project in gradle?


This page gives an introduction to gradle java project, include java plugin in your gradle configuration file, which adds all required tasks by default.

apply plugin: 'java'

Folder structure should be similar to maven java project folder structure.

src/main/java
src/test/java
src/main/resources
src/test/resources
build – all output files will be created here.
build/lib

Add below configuration to define external dependencies using maven.

repositories {
        mavenCentral()
}

dependencies {
        compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
        testCompile group: 'junit', name: 'junit', version: '4.+'
}

The Java plugin by default adds many properties to your project. You are allowed to change these values. Here is an example to customize your MANIFEST.MF file:

sourceCompatibility = 1.5
version = '1.0'
jar {
        manifest {
                attributes 'Implementation-Title': 'Gradle Quickstart',
                          	        'Implementation-Version': version
        }
}

Here is the complete sample java project configuration using gradle:

apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.5
version = '1.0'
jar {
        manifest {
                attributes 'Implementation-Title': 'Gradle Quickstart',
                           'Implementation-Version': version
                }
}
repositories {
        mavenCentral()
}
dependencies {
        compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
        testCompile group: 'junit', name: 'junit', version: '4.+'
}
test {
        systemProperties 'property': 'value'
}
uploadArchives {
        repositories {
                flatDir {
                        dirs 'repos'
                }
        }
}

Reference: Gradle Documentation

<< Previous Program 
blog comments powered by Disqus

Gradle configuration examples

  1. Gradle Installation Steps
  2. What is gradle project and task
  3. What is build.gradle file?
  4. How to avoid gradle log messages?
  5. How to define default tasks in Gradle?
  6. How to list all gradle tasks?
  7. How to list gradle project properties?
  8. How to declare a task that depends on other task?
  9. How to create dynamic tasks in Gradle?
  10. How to exclude a task in gradle?
  11. How to create java project in gradle?
Knowledge Centre
Stream and types of Streams
A Stream is an abstraction that either produces or consumes information. There are two types of Streams and they are:

Byte Streams: Provide a convenient means for handling input and output of bytes. Byte Streams classes are defined by using two abstract classes, namely InputStream and OutputStream.

Character Streams: Provide a convenient means for handling input & output of characters. Character Streams classes are defined by using two abstract classes, namely Reader and Writer.
Famous Quotations
The very best thing you can do for the whole world is to make the most of yourself.
-- Wallace Wattles

About Author

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2017 by Nataraja Gootooru. All Rights Reserved.