alef 0.72.0

Opinionated polyglot binding generator for Rust libraries
Documentation
//! `gradle.properties` emitter — configures Gradle toolchain and caching behavior.
//!
//! Emits `gradle.properties` to allow Gradle to auto-detect the host JDK.
//! The Foojay toolchain resolver plugin (configured in settings.gradle.kts)
//! handles automatic JDK downloads when needed.

/// Emit `gradle.properties` with toolchain and cache settings.
///
/// The build cache is on; the configuration cache is emitted commented out because
/// `buildAndroidJniLibs` reads `gradle.taskGraph` from an `onlyIf` and assigns `System.err` to an
/// `Exec` task's `errorOutput`, both of which Gradle rejects at execution time under the
/// configuration cache — and it rejects them by failing the build, not by degrading. Turning it on
/// here would trade a slow build for a broken one. `org.gradle.parallel` is deliberately absent:
/// it parallelises across subprojects, and this project has one module. ~keep
pub fn emit() -> String {
    r#"# Generated by alef. Do not edit by hand.

# Allow Gradle to auto-detect JDK installations on the build machine.
# The Foojay resolver plugin in settings.gradle.kts provides automatic
# JDK download capability when a requested version is not found locally.
org.gradle.java.installations.auto-detect=true

# Increase heap for large multi-project builds.
org.gradle.jvmargs=-Xmx4g

# Reuse task outputs across builds. This is what makes a repeated assembleDebug,
# the shape documentation snippet validation runs before every check, cheap
# instead of a full rebuild each time.
org.gradle.caching=true

# The configuration cache is not enabled by default: the generated
# buildAndroidJniLibs task reads gradle.taskGraph from onlyIf and writes to
# System.err, which the configuration cache rejects by failing the build. Enable
# it only after adapting that task.
# org.gradle.configuration-cache=true
"#
    .to_string()
}

#[cfg(test)]
mod tests {
    /// The build cache is the property that makes a repeated `assembleDebug` cheap, and the
    /// configuration cache must stay commented out while `buildAndroidJniLibs` is incompatible
    /// with it — an accidental uncomment turns every generated Android build into a hard failure.
    #[test]
    fn the_build_cache_is_enabled_and_the_configuration_cache_is_left_opt_in() {
        let properties = super::emit();

        let settings: Vec<&str> = properties
            .lines()
            .map(str::trim)
            .filter(|line| !line.is_empty() && !line.starts_with('#'))
            .collect();

        assert!(
            settings.contains(&"org.gradle.caching=true"),
            "the build cache must be enabled: {settings:?}"
        );
        assert!(
            !settings
                .iter()
                .any(|line| line.starts_with("org.gradle.configuration-cache")),
            "the configuration cache must not be an active setting: {settings:?}"
        );
        assert!(
            properties.contains("# org.gradle.configuration-cache=true"),
            "the configuration cache must still be documented as an opt-in"
        );
    }

    #[test]
    fn toolchain_auto_detection_and_the_heap_setting_survive() {
        let properties = super::emit();

        assert!(properties.contains("org.gradle.java.installations.auto-detect=true"));
        assert!(properties.contains("org.gradle.jvmargs=-Xmx4g"));
    }
}