This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from zoonooz/support-new-configuration
Support new dependency configuration
- Loading branch information
Showing
4 changed files
with
174 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
core/src/test/groovy/com/novoda/gradle/release/TestGeneratePomTask.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package com.novoda.gradle.release | ||
|
||
import org.gradle.testkit.runner.GradleRunner | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.TemporaryFolder | ||
|
||
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS | ||
|
||
class TestGeneratePomTask { | ||
|
||
@Rule public TemporaryFolder testProjectDir = new TemporaryFolder() | ||
private File buildFile | ||
|
||
@Before | ||
void setup() { | ||
buildFile = testProjectDir.newFile('build.gradle') | ||
} | ||
|
||
@Test | ||
void testGeneratePomTaskForJavaLib() { | ||
buildFile << """ | ||
plugins { | ||
id 'java-library' | ||
id 'bintray-release' | ||
} | ||
publish { | ||
userOrg = 'novoda' | ||
groupId = 'com.novoda' | ||
artifactId = 'test' | ||
publishVersion = '1.0' | ||
} | ||
dependencies { | ||
compile 'com.abc:hello:1.0.0' | ||
implementation 'com.xyz:world:2.0.0' | ||
api 'com.xxx:haha:3.0.0' | ||
} | ||
""" | ||
|
||
def result = GradleRunner.create() | ||
.withProjectDir(testProjectDir.root) | ||
.withArguments("generatePomFileForMavenPublication") | ||
.withPluginClasspath() | ||
.build() | ||
|
||
assert result.task(":generatePomFileForMavenPublication").outcome == SUCCESS | ||
|
||
File pomFile = new File(testProjectDir.root, '/build/publications/maven/pom-default.xml') | ||
def nodes = new XmlSlurper().parse(pomFile) | ||
def dependencies = nodes.dependencies.dependency | ||
|
||
assert dependencies.size() == 3 | ||
assert dependencies.find { dep -> dep.artifactId == "hello" && dep.scope == "compile" } != null | ||
assert dependencies.find { dep -> dep.artifactId == "haha" && dep.scope == "compile" } != null | ||
assert dependencies.find { dep -> dep.artifactId == "world" && dep.scope == "runtime" } != null | ||
} | ||
|
||
@Test | ||
void testGeneratePomTaskForAndroidLibrary() { | ||
File manifestFile = new File(testProjectDir.root, "/src/main/AndroidManifest.xml") | ||
manifestFile.getParentFile().mkdirs() | ||
manifestFile.createNewFile() | ||
manifestFile << """ | ||
<manifest package="com.novoda.test"/> | ||
""" | ||
|
||
buildFile << """ | ||
buildscript { | ||
repositories { | ||
jcenter() | ||
google() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:3.0.0' | ||
} | ||
} | ||
plugins { | ||
id 'bintray-release' apply false | ||
} | ||
apply plugin: "com.android.library" | ||
apply plugin: "bintray-release" | ||
android { | ||
compileSdkVersion 26 | ||
buildToolsVersion "26.0.2" | ||
defaultConfig { | ||
minSdkVersion 16 | ||
versionCode 1 | ||
versionName "0.0.1" | ||
} | ||
} | ||
publish { | ||
userOrg = 'novoda' | ||
groupId = 'com.novoda' | ||
artifactId = 'test' | ||
publishVersion = '1.0' | ||
} | ||
dependencies { | ||
compile 'com.abc:hello:1.0.0' | ||
implementation 'com.xyz:world:2.0.0' | ||
api 'com.xxx:haha:3.0.0' | ||
} | ||
""" | ||
|
||
def result = GradleRunner.create() | ||
.withProjectDir(testProjectDir.root) | ||
.withArguments("generatePomFileForReleasePublication") | ||
.withPluginClasspath() | ||
.build() | ||
|
||
assert result.task(":generatePomFileForReleasePublication").outcome == SUCCESS | ||
|
||
File pomFile = new File(testProjectDir.root, '/build/publications/release/pom-default.xml') | ||
def nodes = new XmlSlurper().parse(pomFile) | ||
def dependencies = nodes.dependencies.dependency | ||
|
||
assert dependencies.size() == 3 | ||
assert dependencies.find { dep -> dep.artifactId == "hello" && dep.scope == "compile" } != null | ||
assert dependencies.find { dep -> dep.artifactId == "haha" && dep.scope == "compile" } != null | ||
assert dependencies.find { dep -> dep.artifactId == "world" && dep.scope == "runtime" } != null | ||
} | ||
} |