Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anddep 1076 when the base modules are connected to project they are delivered transitively #10

Open
wants to merge 4 commits into
base: dev/G-0.5.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions buildSrc/deploy.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ apply plugin: 'maven'
// Function for configuration of dependencies of current android-standard module.
// Context of current module is passed in parameters.

final COMPILE_DEP_TYPE = "compile"
def trueValue = "true"

ext.configureDeploy = { context ->
Expand Down Expand Up @@ -65,34 +66,56 @@ ext.configureDeploy = { context ->
)
}

def artifactGroupId = ArtifactoryConfig.ANDROID_STANDARD_GROUP_ID
def androidStandardArtifactGroupId = ArtifactoryConfig.ANDROID_STANDARD_GROUP_ID
def artifactVersion = Components.getModuleVersion(project.name)
println "uploadAcrhives $artifactName $artifactVersion"

pom.groupId = artifactGroupId
pom.groupId = androidStandardArtifactGroupId
pom.artifactId = artifactName
pom.version = artifactVersion

pom.project {
dependencies {
Components.getAndroidStandardDependencies(project.name).each {
def depArtifactName = it.getArtifactName()
def depArtifactName = it.getName()
def depArtifactVersion = Components.getModuleVersion(it.getName())
def depArtifactScope = it.type.mavenType
def isOptional = !it.type.isTransitive

dependency {
groupId artifactGroupId
groupId androidStandardArtifactGroupId
artifactId depArtifactName
version depArtifactVersion
scope "compile"
scope depArtifactScope
optional isOptional
}
}
}
}
//This code deletes "implementation project("...") dependencies from pom file"
pom.whenConfigured {
p ->
p.dependencies = p.dependencies.findAll {
dep -> dep.groupId != rootDir.name
pom.whenConfigured { p ->
// Deletes "implementation project("...") dependencies from pom file"
p.dependencies = p.dependencies.findAll {
dep -> dep.groupId != rootDir.name
}

// Replaces the third-party dependencies scope in the pom file
// to the type specified in the file components.json
def thirdPartyDependencies = Components.getThirdPartyDependencies(project.name)
p.dependencies.each { dependency ->
if (dependency.groupId != androidStandardArtifactGroupId) {
def thirdPartyDependency = thirdPartyDependencies.find {
dependency.groupId == it.artifactGroupId && dependency.artifactId == it.artifactName
}

if (thirdPartyDependency != null) {
dependency.scope = thirdPartyDependency.type.mavenType
dependency.optional = !thirdPartyDependency.type.isTransitive
} else {
dependency.scope = COMPILE_DEP_TYPE
dependency.optional = true
}
}
}
}
} // repositories.mavenDeployer
}
Expand Down
24 changes: 16 additions & 8 deletions buildSrc/src/main/kotlin/ru/surfstudio/android/build/Components.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import org.gradle.api.GradleException
import ru.surfstudio.android.build.exceptions.component.ComponentNotFoundForStandardDependencyException
import ru.surfstudio.android.build.exceptions.library.LibraryNotFoundException
import ru.surfstudio.android.build.model.Component
import ru.surfstudio.android.build.model.dependency.AndroidStandardDependency
import ru.surfstudio.android.build.model.dependency.Dependency
import ru.surfstudio.android.build.model.dependency.ThirdPartyDependency
import ru.surfstudio.android.build.model.json.ComponentJson
import ru.surfstudio.android.build.model.module.Library
import ru.surfstudio.android.build.model.module.Module
Expand Down Expand Up @@ -94,16 +96,22 @@ object Components {
}

/**
* Get standard artifact names by library name
* Get standard artifacts
*/
@JvmStatic
fun getAndroidStandardDependencies(libraryName: String): List<Library> {
val libs = value.flatMap { it.libraries }
val standardDepNames = libs.find { it.name == libraryName }
?.androidStandardDependencies
?.map(Dependency::name) ?: return emptyList()
return libs.filter { standardDepNames.contains(it.name) }
}
fun getAndroidStandardDependencies(libraryName: String): List<AndroidStandardDependency> =
value.flatMap { it.libraries }
.find { it.name == libraryName }
?.androidStandardDependencies ?: emptyList()

/**
* Get third party artifacts
*/
@JvmStatic
fun getThirdPartyDependencies(libraryName: String): List<ThirdPartyDependency> =
value.flatMap { it.libraries }
.find { it.name == libraryName }
?.thirdPartyDependencies ?: emptyList()

/**
* Get component stability by module name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,16 @@ object DependencyConfigurator {

private fun addThirdPartyDependencies(project: Project, dependencies: List<Dependency>) {
dependencies.forEach {
addDependency(project, it.type, "${it.name}:${libraryVersions[it.name]}")
addDependency(project, it.type.gradleType, "${it.name}:${libraryVersions[it.name]}")
}
}

private fun addAndroidStandardDependencies(project: Project, dependencies: List<Dependency>) {
dependencies.forEach {
if (!isProjectIncluded(project, it.name)) {
addDependency(project, IMPLEMENTATION_DEP_TYPE, getDependencyArtifactoryName(it.name))
addDependency(project, it.type.gradleType, getDependencyArtifactoryName(it.name))
} else {
addDependency(project, IMPLEMENTATION_DEP_TYPE, project.rootProject.project(":${it.name}"))
addDependency(project, it.type.gradleType, project.rootProject.project(":${it.name}"))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import ru.surfstudio.android.build.utils.EMPTY_STRING
*/
data class AndroidStandardDependency(
override val name: String = EMPTY_STRING,
override val type: String = EMPTY_STRING,
override val type: DependencyType = DependencyType.IMPLEMENTATION,
var component: Component = Component()
) : Dependency(name, type)
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import ru.surfstudio.android.build.utils.EMPTY_STRING
*/
open class Dependency(
open val name: String = EMPTY_STRING,
open val type: String = EMPTY_STRING
open val type: DependencyType = DependencyType.IMPLEMENTATION
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ru.surfstudio.android.build.model.dependency

import org.gradle.api.GradleException

/**
* Enum of maven and gradle dependencies ratios
*/
enum class DependencyType(
val gradleType: String,
val mavenType: String,
val isTransitive: Boolean
) {

IMPLEMENTATION("implementation", "runtime", false),
API("api", "compile", true),
COMPILE_ONLY("compileOnly", "provided", false),
RUNTIME_ONLY("runtimeOnly", "runtime", false),
TEST_IMPLEMENTATION("testImplementation", "test", false),
ANDROID_TEST_IMPLEMENTATION("androidTestImplementation", "test", false),
KAPT("kapt", "", true),
KAPT_TEST("kaptTest", "", true);

companion object {

fun fomString(type: String) = values().find { it.gradleType == type }
?: throw GradleException("failed to parse the type of dependency: $type")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ import ru.surfstudio.android.build.utils.EMPTY_STRING
*/
data class ThirdPartyDependency(
override val name: String = EMPTY_STRING,
override val type: String = EMPTY_STRING
) : Dependency(name, type)
override val type: DependencyType = DependencyType.IMPLEMENTATION
) : Dependency(name, type) {

val artifactGroupId = name.substringBefore(':')
val artifactName = name.substringAfter(':')
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ru.surfstudio.android.build.model.json

import ru.surfstudio.android.build.model.dependency.AndroidStandardDependency
import ru.surfstudio.android.build.model.dependency.Dependency
import ru.surfstudio.android.build.model.dependency.DependencyType
import ru.surfstudio.android.build.model.dependency.ThirdPartyDependency
import ru.surfstudio.android.build.utils.EMPTY_STRING

Expand All @@ -15,14 +16,14 @@ data class DependencyJson(

constructor(dependency: Dependency) : this(
name = dependency.name,
type = dependency.type
type = dependency.type.gradleType
)

fun transformToAndroidStandardDependency() = AndroidStandardDependency(
name, type
name, DependencyType.fomString(type)
)

fun transformToThirdPartyDependency() = ThirdPartyDependency(
name, type
name, DependencyType.fomString(type)
)
}