scalapb / sbt-scalapb

Deprecated. Please use https://github.com/thesamet/sbt-protoc
Apache License 2.0
21 stars 5 forks source link

Building with gradle - imports for customizations not found #13

Open qux42 opened 7 years ago

qux42 commented 7 years ago

Hi again, I wanna use Primitive wrappers, but i can't get it working. Compiler says that the import was not found or had errors. I'm using gradle to build the protobuf-messages.

build.gradle:

apply plugin: 'scala'

// protoc
def protoDestDir = 'build/generated-sources/protobuf/'
// proto
def protoDir = new FileNameFinder().getFileNames('src/main/proto/', "*.proto")

configurations {
    scalapbc
}

dependencies {

    scalapbc "com.trueaccord.scalapb:scalapbc_${scalaVersion}:0.5.43"
    compile "com.trueaccord.scalapb:scalapb-runtime_${scalaVersion}:0.5.43"
}

task scalapbc << {
    mkdir(protoDestDir)

    javaexec {
        main = 'com.trueaccord.scalapb.ScalaPBC'
        classpath = configurations.scalapbc
        args = [ "--proto_path=${file('src/main/proto').absolutePath}", "--scala_out=single_line_to_string:${protoDestDir}"] +  protoDir
    }
}

sourceSets {
    main {
        scala {
            srcDirs = ['build/generated-sources/protobuf/', 'src/main/scala/', 'src/main/java']
        }
        java {
            srcDirs = []
        }
    }
    test {
        scala {
            srcDirs = ['build/generated-sources/protobuf/','src/main/scala/', 'src/test/java']
        }
        java {
            srcDirs = []
        }
    }
}
compileScala {
    dependsOn scalapbc
}
clean {
    delete protoDestDir
}

the message:

syntax = "proto3";

package com.miele.mcs.business.protobuf;

import "scalapb/scalapb.proto";
import "google/protobuf/wrappers.proto";

option (scalapb.options) = {
  primitive_wrappers: true
};

message ... {
    int64 ... = 1;
}

/**
 * Tell the actor to update the user agent of the host.
 */
message ... {
    int64 ... = 1;
    string ... = 2;
}

The compiler doesn't find both imports. Are there dependencies missing?

thesamet commented 7 years ago

When using scalapbc it's up to you to provide scalapb.proto and wrappers.proto to protoc. You need to make those files available somewhere in the file system and pass that location via --proto_path.