Skip to content

Commit

Permalink
Add generated code to sources jar (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewparmet authored May 19, 2020
1 parent 0e04ecf commit 032b4d3
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
14 changes: 4 additions & 10 deletions buildSrc/src/main/kotlin/RemotePublishing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
* limitations under the License.
*/

import com.toasttab.protokt.shared.kotlin
import com.toasttab.protokt.shared.main
import io.codearte.gradle.nexus.NexusStagingExtension
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.tasks.PublishToMavenRepository
Expand Down Expand Up @@ -108,11 +106,8 @@ fun Project.enablePublishing(defaultJars: Boolean = true) {
}

if (defaultJars) {
tasks.register<Jar>("sourcesJar") {
dependsOn("classes")

from(this@enablePublishing.the<JavaPluginConvention>().sourceSets.main.kotlin)
archiveClassifier.set("sources")
configure<JavaPluginExtension> {
withSourcesJar()
}

tasks.register<Jar>("javadocJar") {
Expand All @@ -124,10 +119,9 @@ fun Project.enablePublishing(defaultJars: Boolean = true) {
publications {
create<MavenPublication>("sources") {
from(components.getByName("java"))
artifact(tasks.getByName("sourcesJar"))
artifact(tasks.getByName("javadocJar"))
artifactId = project.name
version = "$version"
version = "${project.version}"
groupId = "$group"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ import com.google.protobuf.gradle.plugins
import com.google.protobuf.gradle.protobuf
import com.google.protobuf.gradle.protoc
import com.google.protobuf.gradle.remove
import java.io.File
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.tasks.bundling.Jar
import org.gradle.internal.os.OperatingSystem
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.the

const val KOTLIN_EXTRA_CLASSPATH = "kotlin_extra_classpath"
Expand All @@ -37,8 +40,7 @@ internal fun configureProtobufPlugin(project: Project, ext: ProtoktExtension, bi
project.protobuf {
generatedFilesBaseDir = "${project.buildDir}/generated-sources"

project.the<JavaPluginConvention>().sourceSets.main.kotlin
.srcDirs.add(project.file("$generatedFilesBaseDir/main/protokt"))
configureSources(project, generatedFilesBaseDir)

protoc {
artifact = "com.google.protobuf:protoc:${ext.protocVersion}"
Expand Down Expand Up @@ -75,6 +77,22 @@ internal fun configureProtobufPlugin(project: Project, ext: ProtoktExtension, bi
}
}

private fun configureSources(project: Project, generatedSourcesPath: String) {
val protoktDir = "$generatedSourcesPath/main/protokt"

project.the<JavaPluginConvention>()
.sourceSets.main.kotlin.srcDirs
.add(File(protoktDir))

project.afterEvaluate {
if (project.tasks.findByName("sourcesJar") != null) {
tasks.named<Jar>("sourcesJar").configure {
from(protoktDir)
}
}
}
}

private fun normalizePath(binaryPath: String) =
if (OperatingSystem.current().isWindows) {
// on windows, protoc expects a full, /-separated path to the binary
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 2 additions & 0 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar


# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
Expand Down Expand Up @@ -129,6 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand Down
1 change: 1 addition & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ set CMD_LINE_ARGS=%*

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

Expand Down

0 comments on commit 032b4d3

Please sign in to comment.