gradle和maven根据不同平台使用不同依赖

作者: zengde 分类: 笔记 发布时间: 2017-03-21 06:11

gradle:

apply plugin: 'java'

repositories {
    jcenter()
}

configurations {
    winCompile

    //compileOnly.extendsFrom winCompile
    //testCompile.extendsFrom winCompile // Assuming tests run on the desktop

    windows {
        extendsFrom winCompile
        extendsFrom runtime
    }
}

import org.gradle.internal.os.OperatingSystem;
OperatingSystem osType=OperatingSystem.current();

dependencies {
    compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.11-0.11'
	//runtime(group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.11-0.11', ext: 'jar'){
		//if(osType.isWindows()){
			//classifier='windows-x86'
		//}
		//println(osType.isWindows())
	//}
	//winCompile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.11-0.11', ext: 'jar',classifier:'windows-x86'
}

task getDeps(type: Copy) {
    from sourceSets.main.runtimeClasspath
    into 'dist/lib'
}


maven:

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

	<modelVersion>4.0.0</modelVersion>
	
	<groupId>net.example</groupId>
	<artifactId>test</artifactId>
	<version>1.0-MASTER</version>
	<properties>
		<opencv.version>2.4.11-0.11</opencv.version>
	</properties>
	<profiles>
		<profile>
			<id>platform-1</id>
			<activation>
			  <os>
				<family>Windows</family>
				<arch>x86</arch>
			  </os>
			</activation>
			<dependencies>
				<dependency>
					<groupId>org.bytedeco.javacpp-presets</groupId>
					<artifactId>opencv</artifactId>
					<version>${opencv.version}</version>
					<type>jar</type>
					<classifier>windows-x86</classifier>
					<scope>runtime</scope>
				</dependency>
			</dependencies>
		</profile>
		<profile>
			<id>platform-2</id>
			<activation>
			  <os>
				<family>Windows</family>
				<arch>amd64</arch>
			  </os>
			</activation>
			<dependencies>
				<dependency>
					<groupId>org.bytedeco.javacpp-presets</groupId>
					<artifactId>opencv</artifactId>
					<version>${opencv.version}</version>
					<type>jar</type>
					<classifier>windows-x86_64</classifier>
					<scope>runtime</scope>
				</dependency>
			</dependencies>
		</profile>
		<profile>
			<id>platform-3</id>
			<activation>
			  <os>
				<family>Linux</family>
				<arch>x86</arch>
			  </os>
			</activation>
			<dependencies>
				<dependency>
					<groupId>org.bytedeco.javacpp-presets</groupId>
					<artifactId>opencv</artifactId>
					<version>${opencv.version}</version>
					<type>jar</type>
					<classifier>linux-x86</classifier>
					<scope>runtime</scope>
				</dependency>
			</dependencies>
		</profile>
		<profile>
			<id>platform-4</id>
			<activation>
			  <os>
				<family>Linux</family>
				<arch>x64</arch>
			  </os>
			</activation>
			<dependencies>
				<dependency>
					<groupId>org.bytedeco.javacpp-presets</groupId>
					<artifactId>opencv</artifactId>
					<version>${opencv.version}</version>
					<type>jar</type>
					<classifier>linux-x64</classifier>
					<scope>runtime</scope>
				</dependency>
			</dependencies>
		</profile>
		<profile>
			<id>platform-5</id>
			<activation>
			  <os>
				<family>mac</family>
			  </os>
			</activation>
			<dependencies>
				<dependency>
					<groupId>org.bytedeco.javacpp-presets</groupId>
					<artifactId>opencv</artifactId>
					<version>${opencv.version}</version>
					<type>jar</type>
					<classifier>macosx-x86_64</classifier>
					<scope>runtime</scope>
				</dependency>
			</dependencies>
		</profile>
	</profiles>
</project>