Merge pull request #9898 from srzamfir/feature/BAEL-4516_Gradle_source_sets
BAEL-4516 : Gradle Source Sets
This commit is contained in:
commit
1e167f7fa4
gradle-5
settings.gradle
source-sets
.gitignorebuild.gradle
src
itest/java/com/baeldung/itest
main/java/com/baeldung/main
test/java/com/baeldung/test
@ -1,3 +1,4 @@
|
|||||||
rootProject.name='gradle-5-articles'
|
rootProject.name='gradle-5-articles'
|
||||||
include 'java-exec'
|
include 'java-exec'
|
||||||
include 'unused-dependencies'
|
include 'unused-dependencies'
|
||||||
|
include 'source-sets'
|
1
gradle-5/source-sets/.gitignore
vendored
Normal file
1
gradle-5/source-sets/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/build/
|
67
gradle-5/source-sets/build.gradle
Normal file
67
gradle-5/source-sets/build.gradle
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
|
||||||
|
apply plugin: "eclipse"
|
||||||
|
apply plugin: "java"
|
||||||
|
|
||||||
|
description = "Source Sets example"
|
||||||
|
|
||||||
|
task printSourceSetInformation(){
|
||||||
|
description = "Print source set information"
|
||||||
|
|
||||||
|
doLast{
|
||||||
|
sourceSets.each { srcSet ->
|
||||||
|
println "["+srcSet.name+"]"
|
||||||
|
print "-->Source directories: "+srcSet.allJava.srcDirs+"\n"
|
||||||
|
print "-->Output directories: "+srcSet.output.classesDirs.files+"\n"
|
||||||
|
print "-->Compile classpath:\n"
|
||||||
|
srcSet.compileClasspath.files.each {
|
||||||
|
print " "+it.path+"\n"
|
||||||
|
}
|
||||||
|
println ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets{
|
||||||
|
itest {
|
||||||
|
compileClasspath += sourceSets.main.output
|
||||||
|
runtimeClasspath += sourceSets.main.output
|
||||||
|
java {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test {
|
||||||
|
testLogging {
|
||||||
|
events "passed","skipped", "failed"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation('org.apache.httpcomponents:httpclient:4.5.12')
|
||||||
|
testImplementation('junit:junit:4.12')
|
||||||
|
itestImplementation('com.google.guava:guava:29.0-jre')
|
||||||
|
}
|
||||||
|
|
||||||
|
task itest(type: Test) {
|
||||||
|
description = "Run integration tests"
|
||||||
|
group = "verification"
|
||||||
|
testClassesDirs = sourceSets.itest.output.classesDirs
|
||||||
|
classpath = sourceSets.itest.runtimeClasspath
|
||||||
|
}
|
||||||
|
|
||||||
|
itest {
|
||||||
|
testLogging {
|
||||||
|
events "passed","skipped", "failed"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
configurations {
|
||||||
|
itestImplementation.extendsFrom(testImplementation)
|
||||||
|
itestRuntimeOnly.extendsFrom(testRuntimeOnly)
|
||||||
|
}
|
||||||
|
|
||||||
|
eclipse {
|
||||||
|
classpath {
|
||||||
|
plusConfigurations+=[configurations.itestCompileClasspath]
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.baeldung.itest;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.baeldung.main.SourceSetsObject;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
public class SourceSetsItest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenImmutableList_whenRun_ThenSuccess() {
|
||||||
|
|
||||||
|
SourceSetsObject underTest = new SourceSetsObject("lorem", "ipsum");
|
||||||
|
List<String> someStrings = ImmutableList.of("Baeldung", "is", "cool");
|
||||||
|
|
||||||
|
assertThat(underTest.getUser(), is("lorem"));
|
||||||
|
assertThat(underTest.getPassword(), is("ipsum"));
|
||||||
|
assertThat(someStrings.size(), is(3));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.baeldung.main;
|
||||||
|
|
||||||
|
public class SourceSetsMain {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Hell..oh...world!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.baeldung.main;
|
||||||
|
|
||||||
|
public class SourceSetsObject {
|
||||||
|
|
||||||
|
private final String user;
|
||||||
|
private final String password;
|
||||||
|
|
||||||
|
public SourceSetsObject(String user, String password) {
|
||||||
|
this.user = user;
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.baeldung.test;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.baeldung.main.SourceSetsObject;
|
||||||
|
|
||||||
|
public class SourceSetsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenRun_ThenSuccess() {
|
||||||
|
|
||||||
|
SourceSetsObject underTest = new SourceSetsObject("lorem", "ipsum");
|
||||||
|
|
||||||
|
assertThat(underTest.getUser(), is("lorem"));
|
||||||
|
assertThat(underTest.getPassword(), is("ipsum"));
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user