Skip to content

Commit

Permalink
Fix #55: superpom.isTestProject
Browse files Browse the repository at this point in the history
  • Loading branch information
tlinkowski committed Aug 26, 2019
1 parent f026ce9 commit 2cafa61
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ package pl.tlinkowski.gradle.my.superpom.shared.extension
* @author Tomasz Linkowski
*/
open class MySuperpomExtension {

/**
* If `true`, a project will get all the test dependencies with `api` instead of `testImplementation` scope.
*/
var isTestProject = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package pl.tlinkowski.gradle.my.superpom.shared.internal

import org.ajoberstar.grgit.Grgit
import org.gradle.api.Project
import org.gradle.kotlin.dsl.*
import pl.tlinkowski.gradle.my.superpom.shared.extension.MySuperpomExtension

/**
* Marks that we truly want to release.
Expand All @@ -38,3 +40,12 @@ internal val Project.isDryRunRelease
*/
internal val Project.grgit
get() = property("grgit") as Grgit

/**
* Provides [MySuperpomExtension] instance for given project (works for **subprojects** only).
*
* Querying of this extension should always be done in [Project.afterEvaluate] to make sure that
* the values are already set by the build script.
*/
internal val Project.superpom
get() = extensions.getByType<MySuperpomExtension>()
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MyCompleteSharedConfigPlugin : AbstractRootPlugin() {
}

subprojects {
extensions.create("superpom", MySuperpomExtension::class)
extensions.create<MySuperpomExtension>("superpom")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.gradle.api.tasks.testing.Test
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import pl.tlinkowski.gradle.my.superpom.shared.internal.superpom
import java.util.*

/**
Expand Down Expand Up @@ -60,17 +61,22 @@ internal class TestConfigPlugin : AbstractRootPlugin() {
}
}

/**
* [Project.afterEvaluate] due to [Project.superpom].
*/
private fun Project.configureDependencies() {
dependencies {
val testImplementation by configurations
afterEvaluate {
dependencies {
val kotlinVersion: String by project
val spockVersion: String by project
val groovyVersion: String by project

val kotlinVersion: String by project
val spockVersion: String by project
val groovyVersion: String by project
val scope = if (superpom.isTestProject) "api" else "testImplementation"

testImplementation(kotlin(module = "stdlib-jdk8", version = kotlinVersion))
testImplementation(group = "org.spockframework", name = "spock-core", version = spockVersion)
testImplementation(group = "org.codehaus.groovy", name = "groovy-all", version = groovyVersion)
scope(kotlin(module = "stdlib-jdk8", version = kotlinVersion))
scope(group = "org.spockframework", name = "spock-core", version = spockVersion)
scope(group = "org.codehaus.groovy", name = "groovy-all", version = groovyVersion)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2019 Tomasz Linkowski.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pl.tlinkowski.sample.test;

import org.spockframework.lang.Wildcard;

/**
* @author Tomasz Linkowski
*/
public final class Sample {

public static final Wildcard WILDCARD = Wildcard.INSTANCE;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2019 Tomasz Linkowski.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2019 Tomasz Linkowski.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

superpom {
isTestProject = true
}

0 comments on commit 2cafa61

Please sign in to comment.