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 

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
You can never get enough of what you don’t really need.
-- Eric Hoffer

About Author

I'm Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment.

If you come across any mistakes or bugs, please email me to [email protected].

Most Visited Pages

Other Interesting Sites

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