| @@ -20,39 +20,29 @@ maven: | |||||
| mirrors: | mirrors: | ||||
| - "https://repo.maven.apache.org/maven2" | - "https://repo.maven.apache.org/maven2" | ||||
| # Specify which kotlin versions to fetch. | |||||
| kotlin: | |||||
| 1.8.20: | |||||
| # Plugins specific to this kotlin version. See `general` section for details. | |||||
| # Specify configurations of kotlin version, plugins, and packages. For most packages the kotlin version doesn't matter. | |||||
| configurations: | |||||
| # A kotlin version without specific plugins and packages. This fetches the bare minimum of | |||||
| # packages and plugins to be able to use that kotlin version. | |||||
| - kotlin-version: "1.7.20" | |||||
| - kotlin-version: "1.8.20" | |||||
| # Plugins specific to this kotlin version, listed with their plugin ID, not the full package name. | |||||
| # Plugin versions can be a single version as a string, or a list of strings to fetch multiple versions. | |||||
| plugins: | plugins: | ||||
| com.expediagroup.graphql: ["7.0.0-alpha.5", "6.5.2"] | com.expediagroup.graphql: ["7.0.0-alpha.5", "6.5.2"] | ||||
| # Packages specific to this kotlin version. See `general` section for details. | |||||
| org.panteleyev.jpackageplugin: "1.5.2" | |||||
| # Packages specific to this kotlin version, listed either with their full name as a key, or split into group and artifact. | |||||
| # Package versions can be a single version as a string, or a list of strings to fetch multiple versions. | |||||
| packages: | packages: | ||||
| org.slf4j:slf4j-api: "2.1.0" | org.slf4j:slf4j-api: "2.1.0" | ||||
| # A kotlin version without specific plugins and packages. | |||||
| 1.8.0: {} | |||||
| 1.7.20: | |||||
| packages: | |||||
| org.slf4j:slf4j-api: "2.0.7" | |||||
| # Packages and plugins that doesn't require a specific kotlin version. | |||||
| general: | |||||
| # The kotlin version to use (doesn't matter much, use the newest stable version). | |||||
| _kotlin-version: "1.8.20" | |||||
| plugins: | |||||
| # Plugins are listed with their plugin ID, not the full package name. | |||||
| # Plugin versions can be a single version as a string, or a list of strings to fetch multiple versions. | |||||
| org.panteleyev.jpackageplugin: "1.5.2" | |||||
| packages: | |||||
| # Packages are listed either with their full name as a key, or split into group and artifact. | |||||
| # Package versions can be a single version as a string, or a list of strings to fetch multiple versions. | |||||
| org.jetbrains.kotlinx:kotlinx-datetime: "0.4.0" | |||||
| com.expediagroup: | |||||
| # When splitting into group and artifact, the default versions for the group can be specified. | |||||
| # Using an empty list as the version for an artifact implies that the default versions should be used. | |||||
| _versions: ["7.0.0-alpha.6", "6.5.2"] | |||||
| graphql-kotlin-ktor-server: ["7.0.0-alpha.6"] # Uses only the specified version | |||||
| graphql-kotlin-client: [] # Uses the default versions | |||||
| graphql-kotlin-client-generator: [] # Uses the default versions | |||||
| org.jetbrains.kotlinx:kotlinx-datetime: "0.4.0" | |||||
| com.expediagroup: | |||||
| # When splitting into group and artifact, the default versions for the group can be specified. | |||||
| # Using an empty list as the version for an artifact implies that the default versions should be used. | |||||
| _versions: ["7.0.0-alpha.6", "6.5.2"] | |||||
| graphql-kotlin-ktor-server: ["7.0.0-alpha.6"] # Uses only the specified version | |||||
| graphql-kotlin-client: [] # Uses the default versions | |||||
| graphql-kotlin-client-generator: [] # Uses the default versions | |||||
| ``` | ``` | ||||
| @@ -7,23 +7,29 @@ maven: | |||||
| - "https://registry.quarkus.io/maven" | - "https://registry.quarkus.io/maven" | ||||
| - "https://plugins.gradle.org/m2" | - "https://plugins.gradle.org/m2" | ||||
| kotlin: | |||||
| 1.8.20: | |||||
| configurations: | |||||
| # Specify configurations where the packages/plugins depend on a specific kotlin version. | |||||
| - kotlin-version: "1.8.20" | |||||
| plugins: | plugins: | ||||
| com.expediagroup.graphql: ["7.0.0-alpha.5", "6.5.2"] | com.expediagroup.graphql: ["7.0.0-alpha.5", "6.5.2"] | ||||
| 1.8.0: {} | |||||
| 1.7.20: | |||||
| - kotlin-version: "1.8.0" | |||||
| - kotlin-version: "1.7.20" | |||||
| packages: | packages: | ||||
| org.slf4j:slf4j-api: "2.0.7" | org.slf4j:slf4j-api: "2.0.7" | ||||
| general: | |||||
| _kotlin-version: "1.8.20" | |||||
| plugins: | |||||
| org.panteleyev.jpackageplugin: "1.5.2" | |||||
| packages: | |||||
| org.jetbrains.kotlinx:kotlinx-datetime: "0.4.0" | |||||
| com.expediagroup: | |||||
| _versions: ["7.0.0-alpha.6", "6.5.2"] | |||||
| graphql-kotlin-ktor-server: ["7.0.0-alpha.6"] | |||||
| graphql-kotlin-client: [] | |||||
| graphql-kotlin-client-generator: [] | |||||
| # The default configuration, where the kotlin version doesn't matter. | |||||
| # This is kept as a separate configuration to make the ones above more obvious and easier to maintain. | |||||
| # | |||||
| # Most packages should be placed here. | |||||
| - kotlin-version: "1.8.20" | |||||
| plugins: | |||||
| org.panteleyev.jpackageplugin: "1.5.2" | |||||
| packages: | |||||
| org.jetbrains.kotlinx:kotlinx-datetime: "0.4.0" | |||||
| com.expediagroup: | |||||
| _versions: ["7.0.0-alpha.6", "6.5.2"] | |||||
| graphql-kotlin-ktor-server: ["7.0.0-alpha.6"] | |||||
| graphql-kotlin-client: [] | |||||
| graphql-kotlin-client-generator: [] | |||||
| @@ -1,3 +1,5 @@ | |||||
| from typing import Optional | |||||
| import yaml | import yaml | ||||
| import logging | import logging | ||||
| from dataclasses import dataclass | from dataclasses import dataclass | ||||
| @@ -7,21 +9,21 @@ logger = logging.getLogger(__name__) | |||||
| @dataclass | @dataclass | ||||
| class KotlinVersion: | |||||
| version: str | |||||
| class Configuration: | |||||
| name: str | name: str | ||||
| kotlin_version: str | |||||
| plugins: dict[str, str] | plugins: dict[str, str] | ||||
| packages: list[str] | packages: list[str] | ||||
| @dataclass | @dataclass | ||||
| class Config: | class Config: | ||||
| kotlin_versions: list[KotlinVersion] | |||||
| configurations: list[Configuration] | |||||
| mirrors: list[str] | mirrors: list[str] | ||||
| def handle_packages(section) -> list[str]: | def handle_packages(section) -> list[str]: | ||||
| ignore = ["_kotlin-version", '_versions'] | |||||
| ignore = ['_versions'] | |||||
| result = [] | result = [] | ||||
| for entry in section: | for entry in section: | ||||
| @@ -75,45 +77,43 @@ def handle_plugins(section) -> dict[str, list[str]]: | |||||
| return result | return result | ||||
| def parse_config(path: Path) -> Config: | |||||
| def parse_config(path: Path) -> Optional[Config]: | |||||
| with path.open('r') as f: | with path.open('r') as f: | ||||
| data = yaml.safe_load(f) | data = yaml.safe_load(f) | ||||
| parsed = {} | |||||
| error: list[str] = [] | |||||
| configurations: list[Configuration] = [] | |||||
| for i, section in enumerate(data.get('configurations')): | |||||
| if (version := section.get('kotlin-version')) is None: | |||||
| error.append(f"Configuration {i} is missing 'kotlin-version'") | |||||
| for version, section in data['kotlin'].items(): | |||||
| plugins = handle_plugins(section.get('plugins', {})) | plugins = handle_plugins(section.get('plugins', {})) | ||||
| packages = handle_packages(section.get('packages', {})) | packages = handle_packages(section.get('packages', {})) | ||||
| parsed[version] = { | |||||
| 'plugins': plugins, | |||||
| 'packages': packages, | |||||
| } | |||||
| # Merge the general plugins and packages with that of the default version | |||||
| if general := data.get('general'): | |||||
| if default_version := general.get('_kotlin-version'): | |||||
| parsed.setdefault(default_version, {}) | |||||
| parsed[default_version]['plugins'].update( | |||||
| handle_plugins(general.get('plugins', {})) | |||||
| ) | |||||
| parsed[default_version]['packages'].extend( | |||||
| handle_packages(general.get('packages', {})) | |||||
| ) | |||||
| else: | |||||
| logger.warning(f'"general" section exists, but "_kotlin-version" is not defined. Skipping.') | |||||
| kotlin_versions = [] | |||||
| configurations.append(Configuration( | |||||
| name=f'{version}-packages', | |||||
| kotlin_version=version, | |||||
| plugins={}, | |||||
| packages=packages | |||||
| )) | |||||
| for version, section in parsed.items(): | |||||
| kotlin_versions.append(KotlinVersion(version, f'version-packages', {}, section['packages'])) | |||||
| for plugin, plugin_versions in section['plugins'].items(): | |||||
| for plugin, plugin_versions in plugins.items(): | |||||
| for plugin_version in plugin_versions: | for plugin_version in plugin_versions: | ||||
| kotlin_versions.append(KotlinVersion(version, f'version-plugins-{plugin}', {plugin: plugin_version}, [])) | |||||
| return Config( | |||||
| kotlin_versions, | |||||
| data.get('maven', {}).get('mirrors', []), | |||||
| ) | |||||
| configurations.append(Configuration( | |||||
| name=f'version-plugins-{plugin}', | |||||
| kotlin_version=version, | |||||
| plugins={plugin: plugin_version}, | |||||
| packages=[] | |||||
| )) | |||||
| if error: | |||||
| for msg in error: | |||||
| logger.error(msg) | |||||
| return None | |||||
| else: | |||||
| return Config( | |||||
| configurations, | |||||
| data.get('maven', {}).get('mirrors', []), | |||||
| ) | |||||
| @@ -4,25 +4,25 @@ import logging | |||||
| from pathlib import Path | from pathlib import Path | ||||
| from maven import get_effective_packages | from maven import get_effective_packages | ||||
| from config import parse_config, KotlinVersion | |||||
| from config import parse_config, Configuration | |||||
| from gradle import create_gradle_build, create_gradle_settings | from gradle import create_gradle_build, create_gradle_settings | ||||
| logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
| async def resolve_kotlin(ident: str, kotlin: KotlinVersion, output_dir: Path, mirrors: list[str], gradle_repo: str): | |||||
| async def resolve_kotlin(ident: str, kotlin: Configuration, output_dir: Path, mirrors: list[str], gradle_repo: str): | |||||
| resolved_packages = [ | resolved_packages = [ | ||||
| resolved | resolved | ||||
| for package in kotlin.packages | for package in kotlin.packages | ||||
| for resolved in await get_effective_packages(package, mirrors) | for resolved in await get_effective_packages(package, mirrors) | ||||
| ] | ] | ||||
| path = output_dir / f"{ident}-kotlin-{kotlin.version}" | |||||
| path = output_dir / f"{ident}-kotlin-{kotlin.kotlin_version}" | |||||
| path.mkdir() | path.mkdir() | ||||
| logger.debug(f'Creating {path}') | logger.debug(f'Creating {path}') | ||||
| logger.debug('Generating build.gradle.kts') | logger.debug('Generating build.gradle.kts') | ||||
| gradle_build = create_gradle_build(kotlin.version, kotlin.plugins, resolved_packages, gradle_repo) | |||||
| gradle_build = create_gradle_build(kotlin.kotlin_version, kotlin.plugins, resolved_packages, gradle_repo) | |||||
| (path / 'build.gradle.kts').write_text(gradle_build) | (path / 'build.gradle.kts').write_text(gradle_build) | ||||
| logger.debug('Generating settings.gradle.kts') | logger.debug('Generating settings.gradle.kts') | ||||
| @@ -33,17 +33,19 @@ async def resolve_kotlin(ident: str, kotlin: KotlinVersion, output_dir: Path, mi | |||||
| async def main(package_list: Path, output_dir: Path, gradle_repo: str) -> None: | async def main(package_list: Path, output_dir: Path, gradle_repo: str) -> None: | ||||
| config = parse_config(package_list) | config = parse_config(package_list) | ||||
| if not config.kotlin_versions: | |||||
| print('No packages defined, nothing to do.') | |||||
| if not config: | |||||
| print('Error in configuration') | |||||
| if not config.configurations: | |||||
| print('No configurations defined, nothing to do.') | |||||
| elif not config.mirrors: | elif not config.mirrors: | ||||
| print('No mirrors defined. Add maven.mirrors in the config file.') | print('No mirrors defined. Add maven.mirrors in the config file.') | ||||
| else: | else: | ||||
| for i, kotlin in enumerate(config.kotlin_versions): | |||||
| logger.info(f'Resolving kotlin {kotlin.version}') | |||||
| for i, configuration in enumerate(config.configurations): | |||||
| logger.info(f'Resolving kotlin {configuration.kotlin_version}') | |||||
| try: | try: | ||||
| await resolve_kotlin(str(i), kotlin, output_dir, config.mirrors, gradle_repo) | |||||
| await resolve_kotlin(str(i), configuration, output_dir, config.mirrors, gradle_repo) | |||||
| except: | except: | ||||
| logger.exception(f'Error resolving kotlin version {kotlin.version}') | |||||
| logger.exception(f'Error resolving kotlin version {configuration.kotlin_version}') | |||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||