简体   繁体   中英

How to add a source code file as a build dependency and/or access definitions in a source file?

I have:

plugins {
    id 'java'
    id 'net.bytebuddy.byte-buddy-gradle-plugin' version "$byteBuddyVersion"
}

byteBuddy {
    transformation {
        plugin = io.github.leoframework.testing.Logger.class
    }
}

Logger.java is part of the project and in the Byte Buddy plugin. I need to reference which file/class within my build script to invoke the plugin. The class file needs to be loaded after compiling Logger.java .

If it's part of the current project, it is not that trivial, unfortunately. Gradle is executed in its own JVM process that is run before the compilation what makes this somewhat a chicken and egg problem.

To overcome this, you'd need to compile the classes first, then define a subproject that depend on these classes dynamically and then execute the plugin from this subproject once the dependent classes are available.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM